Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

The NumberFormat Class  RSS feed

 
sweety singh
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!