Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

rounding numbers to 2 decimal places

843789Apr 21 2010 — edited Apr 22 2010
Hello programming community,

I have the following code to round my answers to 2 decimal places:
double roundedValue;
DecimalFormat twoDForm = new DecimalFormat ("#.##");
roundedValue = Double.valueOf(twoDForm.format(value));
The code works great and what i expect it to do. When I pass in really big decimal numbers (2.55555668) it correctly rounds it (2.56) but when it rounds the number and the last decimal is a zero it does not display this. (if the number ends up rounding to 4.50 , i want it to display it this way but it ends up getting rid of the 0. )

If anyone has any ideas for a way to fix this please let me know.

Thanks.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 20 2010
Added on Apr 21 2010
18 comments
708 views