dcsimg
how to round double value using java
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   jessly_sim
Posted On:   Wednesday, June 6, 2001 08:06 PM

i would like to know how to round the double to certain decimal.
e.g 1.33333333 to 1.333

Re: how to round double value using java

Posted By:   Anonymous  
Posted On:   Wednesday, June 6, 2001 11:13 PM

Hi,
Use Class BigDecimal.

sample code ...



double val = 1.33333333;
BigDecimal bd = new BigDecimal(val);
bd = bd.setScale(3,BigDecimal.ROUND_HALF_UP);//pass the no. of decimal places to be rounded(3 in this case)

System.out.println("Rounded value :"+ bd.doubleValue());
About | Sitemap | Contact