Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Format numbers using DecimalFormat

Status
Not open for further replies.

fthibaut

Programmer
Apr 23, 2001
2
DK
Hi,

I'm trying to use DecimalFormat to format numbers according to the current locale. I don't understand why I don't have the output that I expect.
The code I'm using looks like this :

DecimalFormat df = new DecimalFormat("#.##0");
String output = df.format(5.0);
System.out.println(value + " " + pattern + " " + output);

I was expecting to have the number formatted like that : 5,000
What I get is : 5,0

Is it a bug or am I missing something ?

Thanks in advance.
 
As far as i read in the java doc, the # defines that the value can be absent. If you'll use the pattern "0.000" will be convert 5,0 -> 5,000.

Hope this helps,
Steven.
 
You're right, my pattern was not correct...

Thank you,

/Franck
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top