This week's book giveaways are in the iOS and Features new in Java 8 forums.
We're giving away four copies each of Barcodes with iOS: Bringing together the digital and physical worlds and Core Java for the Impatient and have the authors on-line!
See this thread and this one for details.
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

Win a copy of Barcodes with iOS this week in the iOS forum
or Core Java for the Impatient in the Java 8 forum!

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