Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Formatting floating point numbers

 
O. Ziggy
Ranch Hand
Posts: 430
Android Debian VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 58
C++ Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic