Why can't float compile %? So how to get the surplus of decimal divisions? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Why can't float compile %? So how to get the surplus of decimal divisions?

11th Nov 2018, 10:04 PM
milad
milad - avatar
2 Answers
+ 1
I answered this a while ago, but it would probably be hard to find. The modulo operator (%) calculates the integer remainder of division of two integers. If you think about it, a float contains the remainder of a division in the numbers after the decimal. For example, 3 % 2 will give 1 and 3 / 2 will give 1.5 as a float. 0.5 x 2 is 1, the integer remainder. This is why it's not necessary or wanted for float division.
11th Nov 2018, 10:54 PM
Zeke Williams
Zeke Williams - avatar
0
Hello. The % is only aviable for two integer. The result of the the division of floats is another float.
11th Nov 2018, 10:13 PM
Timo Heinzelmann
Timo Heinzelmann - avatar