+ 5

When you divide two integers and there is a remainder, does C++ truncate or floor the answer if it is a decimal?

28th Dec 2016, 8:46 PM
Madison Sawyer
Madison Sawyer - avatar
7 Answers
+ 6
Even if it's below zero?
28th Dec 2016, 8:56 PM
Valen.H. ~
Valen.H. ~ - avatar
+ 6
-5/2 ?
28th Dec 2016, 8:57 PM
Valen.H. ~
Valen.H. ~ - avatar
+ 5
The answer would be automatically floored.
28th Dec 2016, 8:54 PM
Greg Ortiz
Greg Ortiz - avatar
+ 3
I stand corrected, it is better to use the term truncated in both instances (positive and negative). Although in positive integers it does mathematically floor the value, but in negative integers it will truncate the decimal remainder. Thus it is better to use the term truncate.
28th Dec 2016, 9:58 PM
Greg Ortiz
Greg Ortiz - avatar
+ 2
Yes, 1 / 2 would result into a 0.
28th Dec 2016, 8:56 PM
Greg Ortiz
Greg Ortiz - avatar
+ 2
Awesome! Thank you Greg!
29th Dec 2016, 4:52 AM
Madison Sawyer
Madison Sawyer - avatar
+ 2
if your answers are in decimal, then the data type float must be used
31st Dec 2016, 3:41 PM
Blake12
Blake12 - avatar