Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,894 questions

51,825 answers

573 users

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
...