Here you can find the source of formatFloatValue(float value)
static public String formatFloatValue(float value)
//package com.java2s; import android.util.Log; public class Main { public static final int DemicalLength = 3; static public String formatFloatValue(float value) { if (value <= 0.0f) { return "0"; }// w ww . j a v a2 s . c o m // TODO: handle the case as: 5.232E-4 ??? //Float d = new Float(value); //String str = d.toString(); String str = String.valueOf(value); Log.d("", " formatFloatValue" + str); int index = str.indexOf('.'); if (index < 0) { return str; } String valueStr; String demicalStr = str.substring(index + 1); if (demicalStr.length() > DemicalLength) { valueStr = new String(str.substring(0, index + DemicalLength)); } else { valueStr = str; } return valueStr; } }