wood burning stoves 2.0*
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


Win a copy of Java 8 in Action this week in the Java 8 forum!
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.
 
jQuery in Action, 2nd edition
 
subject: Formatting floating point numbers
 
Similar Threads
Format Doubt
ExamLab Question - Formatting
validation of input field
java script to validate decimal point
Packed decimal conversion - Java