Java Float Number Create toFloat(Object value)

Here you can find the source of toFloat(Object value)

Description

Convert an Object to a Float.

License

Apache License

Declaration

public static Float toFloat(Object value) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    /**//from  w w  w  . j  av  a  2 s  .co  m
     * Convert an Object to a Float.
     */
    public static Float toFloat(Object value) {
        if (value == null)
            return null;
        if (value instanceof Float)
            return (Float) value;
        if (value instanceof String) {
            if ("".equals((String) value))
                return null;
            return new Float((String) value);
        }
        if (value instanceof Number)
            return new Float(((Number) value).floatValue());

        return new Float(value.toString());
    }

    /**
     * Convert an Object to a float, or 0 if it is null.
     */
    public static float floatValue(Object value) {
        if (value == null)
            return 0.0f;
        return toFloat(value).floatValue();
    }
}

Related

  1. toFloat(Object val)
  2. toFloat(Object val)
  3. toFloat(Object value)
  4. toFloat(Object value)
  5. toFloat(Object value)
  6. toFloat(short half)
  7. toFloat(short[] arr)
  8. toFloat(short[] src)
  9. toFloat(String parameter)