Android String to Float Convert parseFloat(String value)

Here you can find the source of parseFloat(String value)

Description

parse Float

Declaration

public static float parseFloat(String value) 

Method Source Code

//package com.java2s;
import java.math.BigDecimal;

public class Main {
    public static float parseFloat(String value) {
        float result = (float) 0.00;
        if (value.length() > 0) {
            try {
                result = round(Float.parseFloat(value), 1);
            } catch (Exception e) {
                return (float) 0.00;
            }//from  w  w  w .  j  ava  2s  . c o  m
        }
        return result;
    }

    public static float round(float d, int decimalPlace) {
        BigDecimal bd = new BigDecimal(Float.toString(d));
        bd = bd.setScale(decimalPlace, BigDecimal.ROUND_FLOOR);
        return bd.floatValue();
    }
}

Related

  1. isFloat(String str)
  2. isFloat(String str, int precision)
  3. getFloatValue(double val, int len)
  4. parseFloat(String string, float defValue)
  5. TryParse(String str, float defaultFloat)