T
TomislaW
Decimal.Round(num,0) method returns:
4 for 4.4
4 for 4.5
5 for 4.6
I need 5 for 4.5 is there any other way for rounding?
4 for 4.4
4 for 4.5
5 for 4.6
I need 5 for 4.5 is there any other way for rounding?
TomislaW said:Decimal.Round(num,0) method returns:
4 for 4.4
4 for 4.5
5 for 4.6
I need 5 for 4.5 is there any other way for rounding?
4 for 4.4
4 for 4.5
5 for 4.6
I need 5 for 4.5 is there any other way for rounding?
{
return ( int )( value + 0.5 );
}
Morten Wennevik said:Just to add to the other posts,
I think the problem is that the system actually reads 4.499999999...
something when input 4.5 so the rounding is as far as the computer knows
"correctly" done to 4.0, even though this is not the desired result.
Morten said:Just to add to the other posts,
I think the problem is that the system actually reads 4.499999999...
something when input 4.5 so the rounding is as far as the computer
knows "correctly" done to 4.0, even though this is not the desired
result.
Morten Wennevik said:My bad, the doc does indeed say exactly that. I read that page, but
somehow I misread 2.345-> 2.35 and thought nothing of it.
But wasn't something similar being discussed a few months ago?
I remember that thread saying something about x.5 being stored as
0.499999999999917354246 or something.
Ron Allen said:A Decimal isn't stored as floating point though. It is based on scaled
integers so all of them have an exact representation.