Android examples for java.text:NumberFormat
format Number to string with NumberFormat
import java.math.RoundingMode; import java.text.DecimalFormat; import java.text.NumberFormat; public class Main{ public static String format(Number n) { NumberFormat format = DecimalFormat.getInstance(); format.setRoundingMode(RoundingMode.HALF_EVEN); format.setMinimumFractionDigits(0); format.setMaximumFractionDigits(1); return format.format(n); }//from w w w . j av a 2s .c o m }