times 100

1.5555 * 100 = 155.55

round

156

divide by 100

1.56

Printable View

- 06-12-2009ಠ_ಠ
- 06-12-2009tabstop
- 06-12-2009brewbuck
And of course, it should be noted that due to the inaccuracy of floats, you still might not get exactly the answer you expect.

For instance, round( 1.234 * 100.0 ) / 100.0 might give 1.229999999, which would be printed as 1.22 if you are limiting the number of digits.

But that's just the way the cookie crumbles. - 06-13-2009iMalc
Bleh - brainfart. For ome reason I thought it didn't mention rounding.

- 06-23-2009m37h0dCode:
`int round(double f)`

{

unsigned int i = fabs(f*2);

if(i&1)

{

if(f>0)

{

return (int)++f;

}

return (int)--f;

}

else

{

return (int)f;

}

}

this seems to do the trick, but i thought i'd throw it up in case someone can spot a problem.