Print (1.25%0.5) | Sololearn: Learn to code for FREE!
Nouvelle formation ! Tous les codeurs devraient apprendre l'IA générative !
Essayez une leçon gratuite
- 2

Print (1.25%0.5)

Why I get 0.25 when 0.5 can divide 1.25 0.25 time it is not remainder it is quotient

28th Oct 2021, 7:19 AM
Kana Singh
Kana Singh - avatar
3 Réponses
+ 3
The % gives you whats left after dividing. In your case 1.25 can be divided by 0.5 two times and then there is 0.25 left which can‘t be dicided by 0.5. Thats the value you get back.
28th Oct 2021, 7:36 AM
TheCoder25
TheCoder25 - avatar
+ 2
This happen due to floating point rounding issues. Similar question here. https://stackoverflow.com/questions/14763722/JUMP_LINK__&&__python__&&__JUMP_LINK-modulo-on-floats
28th Oct 2021, 7:36 AM
Maninder $ingh
Maninder $ingh - avatar
+ 2
Maninder $ingh , i can not find a floating point issues in this case. ? can you please give us more details ? using python with: print(f"{(1.25 %0.5):.19f}") gives a result of: 0.2500000000000000000
28th Oct 2021, 5:17 PM
Lothar
Lothar - avatar