View Single Post
  #8 (permalink)  
Old 10-14-2008, 04:54 AM
Norm's Avatar
Norm Norm is offline
Senior Member
 
Join Date: Jun 2008
Location: Heredia, Costa Rica
Posts: 2,225
Norm is on a distinguished road
Quote:
I want to round a double to 2 decimal places.
This code will round a double to 2 decimal places:
double roundFactor = 0.005;
double d = 1.234455 + roundFactor; // round
int x = (int)(d * 100); // to two decimal places, drops rest
d = x / 100.0; // back to double = 1.23
Reply With Quote