Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package org.richfaces.component;
 
 
 import  org.richfaces.log.Logger;
 import  org.richfaces.log.RichfacesLogger;
 
 public final class NumberUtils {
     private static final Logger LOGGER = RichfacesLogger.COMPONENTS.getLogger();
    private NumberUtils() {
    }

    
Converts value attr to number value

Parameters:
v - value attr
Returns:
result
    public static Number getNumber(Object v) {
        Number result = null;
        if (v != null) {
            try {
                if (v instanceof String) { // String
                    result = Double.parseDouble((Stringv);
                } else {
                    Number n = (Numberv;
                    if ((n instanceof BigDecimal) || (n instanceof Double// Double
                        // or
                        // BigDecimal
                        || (n instanceof Float)) {
                        result = n.floatValue();
                    } else if (n instanceof Integer || n instanceof Long) { // Integer
                        result = n.longValue();
                    }
                }
            } catch (Exception e) {
                .error(e.getMessage(), e);
            }
            return result;
        }
        return new Integer(0);
    }
New to GrepCode? Check out our FAQ X