• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Round

 
Jackie Wang
Ranch Hand
Posts: 315
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how to round a double to a 2 decimal place?
I am using jdk1.3
Thanks!
 
Pablo Gomes Ludermir
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 250
MS IE Oracle Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic