aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Formatting floating point numbers 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 "Formatting floating point numbers" Watch "Formatting floating point numbers" New topic
Author

Formatting floating point numbers

O. Ziggy
Ranch Hand

Joined: Oct 02, 2005
Posts: 430

The following sample code:



Prints out 2122.4

The format i specified for the above result shows that i asked for one decimal point and 1 character long for the width. I can see the one decimal point (i.e. .4) but why did the specified width not work?
Sebanti Sanyal
Ranch Hand

Joined: Nov 07, 2011
Posts: 58

What you specify is the minimum no. of characters to print. Here the integral part contains 4 characters and along with the fractional part, there are 6 characters to print. Increase the width to 7 to see the difference.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Formatting floating point numbers