File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes floating point precision Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "floating point precision" Watch "floating point precision" New topic

floating point precision

george justin

Joined: Jul 31, 2001
Posts: 25
COULD SOMWEONE P-OSSIBLY TELL ME HOW TO convert floating point data to a precision of 2 decimal points....urgent..pleeeeeeez.
besides using String manipulation....
Bill Tripper

Joined: May 30, 2001
Posts: 24
Theres probably a function to do this which I couldn't find, but how about:
x = Math.round(x * 100) / 100.0;
If x is a double, this will round it to 2 decimal places.
Nathan Pruett

Joined: Oct 18, 2000
Posts: 4121

Here's the function Bill couldn't find: setMaximumFractionDigits( int ) in the java.text.DecimalFormat class...

See this post for more details...

- Nate
[This message has been edited by Nathan Pruett (edited August 23, 2001).]

Write once, run anywhere, because there's nowhere to hide! - /. A.C.
David Weitzman
Ranch Hand

Joined: Jul 27, 2001
Posts: 1365
Nathan, besides using String manipulation
I agree. Here's the link:
subject: floating point precision
It's not a secret anymore!