This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread 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 Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Round" Watch "Round" New topic
Author

Round

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
Thanks!
Pablo Gomes Ludermir
Greenhorn

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)
[]s
Pablo
SCJP14
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
 
Don't get me started about those stupid light bulbs.
 
subject: Round
 
Similar Threads
Google interview questions for java developer
function
Its Moose Day!
Query
JAVA