Java.text.NumberFormat How to use

Source: Internet
Author: User
Tags locale

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

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.