How to get the floating-point remainder (modulo) of the division float numbers x/y using in Python

1 Answer

0 votes
import math

print("fmod(4.3, 2.0) = ", math.fmod(4.3, 2.0))
print("fmod(18.5, 4.2) = ", math.fmod(18.5, 4.3))
print("fmod(5.1, 3.0) = ", math.fmod(5.1, 3.0))
print("fmod(-5.1, 3.0) = ", math.fmod(-5.1, 3.0))
print("fmod(5.1, -3.0) = ", math.fmod(5.1, -3.0))
print("fmod(-5.1, -3.0) = ", math.fmod(-5.1, -3.0))
print("fmod(0.0, 1.0) = ", math.fmod(0, 1.0))
print("fmod(-0.0, 1.0) = ", math.fmod(-0.0, 1.0))


'''
run:

fmod(4.3, 2.0) =  0.2999999999999998
fmod(18.5, 4.2) =  1.3000000000000007
fmod(5.1, 3.0) =  2.0999999999999996
fmod(-5.1, 3.0) =  -2.0999999999999996
fmod(5.1, -3.0) =  2.0999999999999996
fmod(-5.1, -3.0) =  -2.0999999999999996
fmod(0.0, 1.0) =  0.0
fmod(-0.0, 1.0) =  -0.0

'''

 



answered Oct 13, 2017 by avibootz
...