Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Java in General
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
Java in General
Set Decimal Places for a Float value
Steve Dyke
Ranch Hand
Posts: 2206
2
posted 15 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
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: 5008
38
posted 15 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
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: 2206
2
posted 15 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Thanks. The DecimalFormat works great.
Can you smell this for me? I think this tiny ad smells like blueberry pie!
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Dealing with decimal places
[floats and doubles] float f = 80/9; // f=8.0!!
SetPrecision?
Wrapper class question from Danchisolm
2 decimal points VS 1
More...