• Post Reply Bookmark Topic Watch Topic
  • New Topic

Set Decimal Places for a Float value  RSS feed

 
Steve Dyke
Ranch Hand
Posts: 1783
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have float values like 8.0, 3.0, 5.5. I need them to become 8.00, 3.00, 5.50 etc. Nothing I try gives me two decimal places. This is necessary because I use this value in a fixed length string so 8.0 will become 0000800.
 
Norm Radder
Rancher
Posts: 2240
28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are classes to format numberic values to String with a lot of user choices. Look at the DecimalFormat class for example.
 
Steve Dyke
Ranch Hand
Posts: 1783
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks. The DecimalFormat works great.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!