Java Utililty Methods Float Number Parse

List of utility methods to do Float Number Parse

Description

The list of methods to do Float Number Parse are organized into topic(s).

Method

doublereadFloatFromString(String inStr)
Read float data from a string
DecimalFormat dformat = new DecimalFormat("#");
DecimalFormatSymbols dfs = new DecimalFormatSymbols();
dfs.setDecimalSeparator('.');
dformat.setDecimalFormatSymbols(dfs);
String trimStr = inStr.trim();
if (trimStr.startsWith("+")) {
    trimStr = trimStr.substring(1);
ParsePosition pp = new ParsePosition(0);
Number num = dformat.parse(trimStr, pp);
if (null == num) {
    throw new Exception("Invalid Float In TLE");
return num.doubleValue();
Floatstring2float(String arg, Locale loc)
stringfloat
if (arg == null) {
    return null;
NumberFormat nf = NumberFormat.getInstance(loc);
return nf.parse(arg).floatValue();
ObjecttryParseFloat(String floatValue)
try Parse Float
Object parsedValue;
try {
    parsedValue = Float.parseFloat(floatValue);
} catch (NumberFormatException nfe) {
    parsedValue = floatValue;
return parsedValue;
FloattryParseFloat(String value)
Try to parse the string as float or return null if failed
try {
    return Float.parseFloat(value);
} catch (NumberFormatException e) {
    return null;
booleantryParseFloat(String value)
Returns whether or not the String can be parsed as an Float
try {
    Float.parseFloat(value);
} catch (NumberFormatException ex) {
    return false;
return true;
float[]tryParseFloats(String[] in)
Tries to parse an array of floats.
try {
    return parseFloats(in);
} catch (NumberFormatException e) {
    return new float[0];