View Single Post
Old 11-25-2006, 08:15 PM   #29 (permalink)
Sep102
Forum Expert
 
Join Date: Aug 2004
Location: Redmond, WA
Age: 21
Posts: 1,288
Send a message via AIM to Sep102 Send a message via MSN to Sep102
Default

Quote:
Originally Posted by TheOutkastDev
Casting to less precise numeric data type causes truncation, not rounding. That's why there is a Math.Round() function.
That's why I add 0.5 to the value before I truncate it, it pushes x.y to (x + 1).z when y >= 0.5, thus truncating gives x + 1, and it pushes x.y to x.z when y < 0.5, thus truncating gives x.

And, yes, there is a Math.Round(), however most of his examples of code earlier were all C++, thus I gave an answer that would work in a managed or unmanaged environment.

Would you have preferred I wrote it as "round" instead of round?

Last edited by Sep102; 11-25-2006 at 08:21 PM.
Sep102 is offline   Reply With Quote