This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
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 EJB 3 in Action this week in the EJB and other Java EE Technologies 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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Formatting floating point numbers
 
Similar Threads
ExamLab Question - Formatting
Format Doubt
java script to validate decimal point
Packed decimal conversion - Java
validation of input field