Set format to two decimal places: set Minimum Fraction Digits in Java
Description
The following code shows how to set format to two decimal places: set Minimum Fraction Digits.
Example
/*from w w w.ja va2 s . com*/
import java.text.NumberFormat;
public class Main {
public static void main(String[] argv) throws Exception {
NumberFormat nf = NumberFormat.getInstance();
nf.setMinimumFractionDigits(2);
System.out.println("Format with two decimal places: " + nf.format(1234567.678));
}
}
The code above generates the following result.