format Number to string with NumberFormat - Android java.text

Android examples for java.text:NumberFormat

Description

format Number to string with NumberFormat

Demo Code

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

}

Related Tutorials