This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes The NumberFormat Class Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply 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: 35241
    
    7
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).


Android appsImageJ pluginsJava web charts
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: The NumberFormat Class
 
Similar Threads
How to use Locale ?
NumberFormat question
Formating number-Inputs by locale
How to stop Values being cleared JTextField in non-english locales
NumberFormat parsing currency value failure