Click to See Complete Forum and Search --> : decimal


duke1000
March 1st, 2000, 03:52 PM
Hi :o)

I've a value : 3.5463729
But I want to keep only the value : 3.55

Is there a function to round decimals

Thanks !

Duke :-)

Erik
March 2nd, 2000, 03:51 AM
try this

float f = 3.5463729;
f *= 100.0f;
int i = (int)f;//truncate
f = ((float)i) / 100.0f;

//or combine to save typing

f = ((float)((int)(f * 100))) /100.0f;



not tested but it should work. The idea is to move the decimal right 2, truncate, the move the decimal back