How to check if a float is a whole number in Python

2 Answers

0 votes
import math

num1 = 980.0
num2 = 3.14159

print(num1.is_integer())
print(num2.is_integer())
 
 
 
 
'''
run:
 
True
False
  
'''

 



answered Jul 14, 2022 by avibootz
0 votes
import math

num1 = 980.0
num2 = 3.14159

print(num1 % 1 == 0)
print(num2 % 1 == 0)
 
 
 
 
'''
run:
 
True
False
  
'''

 



answered Jul 14, 2022 by avibootz

Related questions

1 answer 136 views
4 answers 385 views
3 answers 176 views
1 answer 150 views
...