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 Round Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Round" Watch "Round" New topic


Jackie Wang
Ranch Hand

Joined: Apr 18, 2002
Posts: 315
how to round a double to a 2 decimal place?
I am using jdk1.3
Pablo Gomes Ludermir

Joined: May 29, 2003
Posts: 12
You can combine those methods in java.lang.Math class:
double ceil(double)
double floor(double)
int round(float)
long round(double)
John Hembree
hired gun
Ranch Hand

Joined: Mar 07, 2003
Posts: 250

You can use a BigDecimal also like this:

Then you can turn this into a function that you call with any number and a decimal place that you want returned: getRoundedDouble( 123.3256 , 2 ) would return 123.33
I agree. Here's the link:
subject: Round
jQuery in Action, 3rd edition