round the decimal places
2 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   ramesh_babu
Posted On:   Thursday, June 7, 2001 01:52 AM

How can I round the decimal places
for a double
eg: double d=3.45678

is there any function available in java
so that i will get d =3.45 by
removing the remaining decimal places

Re: round the decimal places

Posted By:   elango_maragtham  
Posted On:   Thursday, June 7, 2001 06:42 PM

Hi ramesh babu .
i have attached a code to round the decimal to appropriate decimal places ..
It will return a String.

public String test(double number,int decimal){
String pattern = "####";
for(int i=0;iif(i==0)
pattern+=".0";
else
pattern+="0";
}
DecimalFormat df1 = new DecimalFormat(pattern);
System.out.println(number+"--->"+df1.format(number));
return(df1.format(number));
}

To convert this String into double u use (Double.valueOf(String)).doubleValue()method to get double value ...
For any help mail to me elangomca@yahoo.com

and

Re: round the decimal places

Posted By:   Anonymous  
Posted On:   Thursday, June 7, 2001 03:50 AM

Use class BigDecimal
check the previous posting for answer
About | Sitemap | Contact