Daniel Billingsley <db**********@NO.durcon.SPAAMM.com> wrote:
I'm trying to figure out what happens when I cast a double with (int)...
does it round or drop the decimal part?
MS says:
"When you convert from a double or float value to an integral type, the
value is rounded towards zero to the nearest integral value."
Uh... what? I've hard of "rounding to the nearest integral value",
"rounding up", "rounding down", but what in tarnation is "rounded towards
zero"? WHAT zero?
What do you mean, "what zero"? There's only one integral zero as far as
I know!
Take -1.1 as an example:
Round down: -2 (greatest int less than or equal to -1.1)
Round up: -1 (least int greater than or equal to -1.1)
Round to zero: -1
There's also the kind of rounding where -1.6 would go to -2, -1.1 would
go to -1, and -1.5 could go to either depending on the exact rounding
scheme - but casting doesn't do this kind of thing.
--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too