| Author |
Round a double to 2 places of Decimal
|
Angela lewis
Ranch Hand
Joined: Mar 01, 2004
Posts: 100
|
|
I have a double value which is multiplied by another value. I want that the result be in only 2 places of decimal rather than the unnecessary precision i am getting. please suggest.
|
 |
Ali Gohar
Ranch Hand
Joined: Mar 18, 2004
Posts: 572
|
|
You can use java.text.NumberFormat class to do so. You can find the help regarding that from : http://java.sun.com/j2se/1.4.2/docs/api/java/text/NumberFormat.html
|
 |
Rikko Verrijzer
Ranch Hand
Joined: Jul 22, 2003
Posts: 34
|
|
Hi, Perhaps the most simple, but not very subtle solution would be: multiply by 100, call Math.round(double), cast to double and divide by 100. long story short, something like this: roundeDoubleValue = (double)Math.round(someDoubleValue*100)/100; But there might be a better solution though Rikko
|
 |
 |
|
|
subject: Round a double to 2 places of Decimal
|
|
|