File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes The NumberFormat Class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "The NumberFormat Class" Watch "The NumberFormat Class" New topic

The NumberFormat Class

sweety singh
Ranch Hand

Joined: Dec 15, 2007
Posts: 49

float f1 = 123.4567f;
Locale locFR = new Locale("fr"); // France
NumberFormat[] nfa = new NumberFormat[4];

nfa[0] = NumberFormat.getInstance();
nfa[1] = NumberFormat.getInstance(locFR);
nfa[2] = NumberFormat.getCurrencyInstance();
nfa[3] = NumberFormat.getCurrencylnstance(locFR);

for(NumberFormat nf : nfa)

This, on our JVM, produces

123,457 // why a comma has been added here..
123,46 ? // why a comma and a question mark...
Ulf Dittmer

Joined: Mar 22, 2005
Posts: 42965
123,457 // why a comma has been added here..

In France (as in many other countries) the full numbers are separated from the decimals by a comma. Elsewhere -e.g. many English-speaking countries- this is done by a decimal point.
123,46 ? // why a comma and a question mark...

I'm guessing that it's not actually a question mark, but a Euro sign, and that wherever you're printing this can't handle it (the font being used might not have that character, or the output only supports ASCII).
I agree. Here's the link:
subject: The NumberFormat Class
It's not a secret anymore!