Here you can find the source of formatFloat(float number, int numberOfAfterDot)
public static float formatFloat(float number, int numberOfAfterDot)
//package com.java2s; //License from project: Open Source License import java.text.DecimalFormat; public class Main { public static float formatFloat(float number, int numberOfAfterDot) { String format = "."; for (int i = 0; i < numberOfAfterDot; i++) { format += "0"; }//from ww w . j a va 2 s.com DecimalFormat decimalFormat = new DecimalFormat(format); String tmp = decimalFormat.format(number); return Float.parseFloat(tmp); } }