This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js and have Paul Jensen on-line!
See this thread for details.
Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript 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: 42972
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).
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!