NumberFormat is the abstract base class for all numeric formats. This class provides an interface for formatting and parsing numeric values. NumberFormat also provides a definite
Which locale has numeric formatting and how they are named.
Package com.discursive.jccook.collections;
Import Java.text.NumberFormat;
public class Test {
/**
* @param args
*/
public static void Main (string[] args) {
TODO auto-generated Method Stub
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 that the decimal portion of a number agrees to.
setmaximumintegerdigits (int) Sets the maximum number of digits that the integer portion of the value agrees to.
setminimumfractiondigits (int) Sets the minimum number of bits that the decimal portion of a number agrees to.
setminimumintegerdigits (int) Sets the minimum number of digits that the integer portion of the value agrees to.
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 How to use