Java Float Number Create toFloat(Object ob, Float defaultFloat)

Here you can find the source of toFloat(Object ob, Float defaultFloat)

Description

to Float

License

Open Source License

Declaration

public static Float toFloat(Object ob, Float defaultFloat) 

Method Source Code

//package com.java2s;

public class Main {

    public static Float toFloat(Object ob, Float defaultFloat) {

        if (ob == null) {
            return defaultFloat;
        }/*from  w  ww .j  ava  2s. c o  m*/

        if (ob instanceof Integer) {
            return ((Integer) ob).floatValue();
        } else if (ob instanceof Float) {
            return ((Float) ob).floatValue();
        } else if (ob instanceof Double) {
            return ((Double) ob).floatValue();
        } else if (ob instanceof Byte) {
            return ((Byte) ob).floatValue();
        } else {
            try {
                return new Float(ob.toString());
            } catch (Exception e) {
                return defaultFloat;
            }
        }
    }

    public static Float toFloat(Object ob) {
        return toFloat(ob, 0f);
    }
}

Related

  1. toFloat(Object anObj)
  2. toFloat(Object literal)
  3. toFloat(Object o)
  4. toFloat(Object o)
  5. toFloat(Object o)
  6. toFloat(Object obj)
  7. toFloat(Object obj)
  8. toFloat(Object obj)
  9. toFloat(Object obj)