Here you can find the source of format(float f)
public static String format(float f)
//package com.java2s; //License from project: GNU General Public License import java.text.NumberFormat; public class Main { private static NumberFormat numberFormat = NumberFormat.getInstance(); public static String format(float f) { numberFormat.setMaximumFractionDigits(2); return numberFormat.format(f); }//from w ww .ja va2s . c om }