Re: Rounding up (Was Re: Another newbie question...)
Re: Rounding up (Was Re: Another newbie question...)
- Subject: Re: Rounding up (Was Re: Another newbie question...)
- From: Esteban <email@hidden>
- Date: Mon, 28 Jan 2002 21:04:17 -0800
Hi,
Made a mistake in my code listing.
See my comment below.
-------------------------
double myvalue = 123.456, result_value;
int temp_value;
temp_value = (int) (123.456 * 100); //multiplying by 100 gets us
12345.6 which we then cast as an int to get rid of the .6 fractional
part.
//the casting to int of a double is very important in the line above
//temp_value should equal 12345
There should be some rounding up going on around here, sorry overlooked
that part :)
where you round up the temp_value so it ends up as 123.46
result_value = (double)(temp_value/100); //we dont really need to
cast back to a double, but the casting is there for illustration
purposes.
//result_value should be equal 123.45, and we have rounded to
hundredths successfully.
-----------------------
Just look at NSDecimalNumber as John C. and I suggested :) (damn he
beat me to response)
-Esteban