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
Tim Cooke
paul wheaton
Liutauras Vilda
Ron McLeod
Sheriffs:
Jeanne Boyarsky
Devaka Cooray
Paul Clapham
Saloon Keepers:
Scott Selikoff
Tim Holloway
Piet Souris
Mikalai Zaikin
Frits Walraven
Bartenders:
Stephan van Hulst
Carey Brown
Forum:
Java in General
cut off decimals of a float number
Graziani Gabriele
Greenhorn
Posts: 15
posted 21 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
I've to print a float number.
i've a float like 0.02999, how can i cut off the decimals to round it to 0.03 ?
Thanks.
Jim Yingst
Wanderer
Posts: 18671
posted 21 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Check out the DecimalFormat class:
DecimalFormat df1 = new DecimalFormat("0.00"); DecimalFormat df2 = new DecimalFormat("#.##"); double x = 0.1; System.out.println(df1.format(x)); System.out.println(df2.format(x));
"I'm not back." - Bill Harding,
Twister
Whoever got anywhere by being normal? Just ask this exceptional tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
bits manipulation
Format to Doubles
f:convertNumber not working in dataTable context
Legal Data Types
More...