PDA

View Full Version : JAVA Integers


the_usualsuper
12-05-2006, 04:26 AM
I'm just wondering because this has been bothering me for a while,

Does an integer become truncated or does it round up?

Example: (Int)14.7

Does it become 14 or 15?

Aradon
12-05-2006, 06:36 AM
it becomes 14. Doubles, Floats, to Integers round down, otherwise known as being "floored"

I think that's the term.. heh.

Gox
12-05-2006, 08:39 AM
Just to clarify, I believe that casting to an int ((int 14.7)) doesn't actually round at all, either or down. What it does is simply truncate the number removing the decimal, thus producing 14.

i.e. It will read up to the decimal point and then stop giving you 14 as the int value. If you actually wanted to round and store as an int you'd have to add .5 to the number before casting to an int.