*
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 Murach's Java Servlets and JSP this week in the Servlets 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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Round
 
Similar Threads
Google interview questions for java developer
Its Moose Day!
Query
JAVA
function