NumberFormat is the abstract base class for all numeric formats. The class provides an interface for formatting and parsing numeric values, and NumberFormat also provides a way to determine which locale has numeric formatting and their names
public class Test {
public static void Main (string[] args) {
Double mynumber=23323.3323232323;
Double test=0.3434;
GetInstance ()
Returns the default numeric format for the current default locale.
String myString = numberformat.getinstance (). Format (MyNumber);
System.out.println (myString);
Getcurrencyinstance () returns the general format of the current default locale
myString = Numberformat.getcurrencyinstance (). Format (MyNumber);
System.out.println (myString);
Getnumberinstance () returns the common numeric format for the current default locale.
myString = Numberformat.getnumberinstance (). Format (MyNumber);
System.out.println (myString);
Getpercentinstance () returns the percentage format for the current default locale.
myString = Numberformat.getpercentinstance (). Format (test);
System.out.println (myString);
setmaximumfractiondigits (int) Sets the maximum number of digits allowed for the decimal portion of a number.
setmaximumintegerdigits (int) Sets the maximum number of digits allowed for an integer portion of a numeric value.
setminimumfractiondigits (int) Sets the minimum number of digits allowed for the decimal part of a numeric value.
setminimumintegerdigits (int) Sets the minimum number of digits allowed for an integer portion of a numeric value.
NumberFormat format = Numberformat.getinstance ();
Format.setminimumfractiondigits (3);
Format.setmaximumfractiondigits (5);
Format.setmaximumintegerdigits (10);
Format.setminimumintegerdigits (0);
System.out.println (Format.format (2132323213.23266666666));
}
}
The result is:
23,323.332
¥23,323.33
23,323.332
34%
2,132,323,213.23267
Java.text.NumberFormat usage