Java Number to Float numberToFloat(Number n)

Here you can find the source of numberToFloat(Number n)

Description

number To Float

License

Apache License

Declaration

public static Float numberToFloat(Number n) 

Method Source Code

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

public class Main {
    public static Float numberToFloat(Number n) {
        if (n != null) {
            if (n instanceof Integer)
                return ((Integer) n).floatValue();
            else if (n instanceof Float)
                return ((Float) n);
            else if (n instanceof Double)
                return ((Double) n).floatValue();
            else if (n instanceof Short)
                return ((Short) n).floatValue();
            else if (n instanceof Long)
                return ((Long) n).floatValue();
            else//from  w  w w.j  ava  2s  . c  om
                return (Float) n;
        }
        return null;
    }
}

Related

  1. NumberToFloat(final Number value)