Java.text.NumberFormat usage

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.