Here you can find the source of formatFloat(float num)
public static float formatFloat(float num)
//package com.java2s; //License from project: Open Source License import java.text.DecimalFormat; public class Main { public static float formatFloat(float num) { float q = 0f; try {/*from ww w . j a v a 2 s . c o m*/ DecimalFormat df = new DecimalFormat("#.###"); q = Float.parseFloat(df.format(num).replace(",", ".")); } catch (Exception e) { e.printStackTrace(); } return q; } }