aspose file tools*
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
Author

The NumberFormat Class

sweety singh
Ranch Hand

Joined: Dec 15, 2007
Posts: 49
Code:


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)
System.out.println(nf.format(f1));

This, on our JVM, produces

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

Joined: Mar 22, 2005
Posts: 42946
    
  70
123.457
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
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).
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: The NumberFormat Class