Android Utililty Methods String to Float Convert

List of utility methods to do String to Float Convert

Description

The list of methods to do String to Float Convert are organized into topic(s).

Method

doubleString2AmountFloat(String str)
String Amount Float
try {
    String tempStr = NumberFormat.getNumberInstance()
            .format(Long.parseLong(str, 10)).replace(",", "");
    return Long.parseLong(tempStr) / 100.00;
} catch (Exception e) {
    e.printStackTrace();
    return 0.00;
booleanisFloat(String str)
is Float
if (isLong(str)) {
    return true;
Pattern pattern = Pattern.compile("\\d*\\.{1}\\d+");
Matcher isNum = pattern.matcher(str);
if (!isNum.matches()) {
    return false;
return true;
booleanisFloat(String str, int precision)
is Float
String regStr = "\\d*\\.{1}\\d{" + precision + "}";
Pattern pattern = Pattern.compile(regStr);
Matcher isNum = pattern.matcher(str);
if (!isNum.matches()) {
    return false;
return true;
doublegetFloatValue(double val, int len)
get Float Value
if (len <= 0) {
    return val;
int lastVal = (int) (val * (Math.pow(10, len + 1)))
        - ((int) (val * (Math.pow(10, len)))) * 10;
if (lastVal < 5) {
    return ((int) (val * (Math.pow(10, len))))
            / (Math.pow(10, len));
...
floatparseFloat(String string, float defValue)
Parses string to float
try {
    return Float.parseFloat(string);
} catch (NumberFormatException nfe) {
    return defValue;
floatTryParse(String str, float defaultFloat)
Try Parse
try {
    float f = Float.parseFloat(str);
    return f;
} catch (NumberFormatException ex) {
    return defaultFloat;
floatparseFloat(String value)
parse Float
float result = (float) 0.00;
if (value.length() > 0) {
    try {
        result = round(Float.parseFloat(value), 1);
    } catch (Exception e) {
        return (float) 0.00;
return result;