Integer

Sep 12, 2015 at 6:39pm
If a data type is an int and the user inputs a decimal like 3.5 what will happen to the .5 part of the number? Will the number be rounded? Or will the .5 be removed?

Sep 12, 2015 at 6:53pm
closed account (48T7M4Gy)
Try it.
Sep 12, 2015 at 8:07pm
http://en.cppreference.com/w/cpp/language/implicit_cast
A prvalue of floating-point type can be converted to prvalue of any integer type. The fractional part is truncated, that is, the fractional part is discarded. If the value can not fit into the destination type, the behavior is undefined (even when the destination type is unsigned, modulo arithmetic does not apply). If the destination type is bool, this is a boolean conversion (see below).
Topic archived. No new replies allowed.