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,900 questions

51,831 answers

573 users

How to convert floating point number to an integer in Python

4 Answers

0 votes
f = 3.14

print(int(f))

   
   
   
'''
run:
   
3
   
'''

 



answered Apr 23, 2021 by avibootz
0 votes
import math
 
print(math.trunc(0))
print(math.trunc(1))
 
print(math.trunc(3.49))
print(math.trunc(3.5))
print(math.trunc(3.51))

print(math.trunc(-3.99))
 
    
    
    
'''
run:
    
0
1
3
3
3
-3
 
'''

 



answered Apr 23, 2021 by avibootz
0 votes
import math

print(math.ceil(0))
print(math.ceil(1))

print(math.ceil(3.01))
print(math.ceil(3.49))
print(math.ceil(3.5))
print(math.ceil(3.51))

print(math.ceil(-3.99))

   
   
   
'''
run:
   
0
1
4
4
4
4
-3

'''

 



answered Apr 23, 2021 by avibootz
0 votes
import math
 
print(math.floor(0))
print(math.floor(1))
 
print(math.floor(3.49))
print(math.floor(3.5))
print(math.floor(3.51))

print(math.floor(-3.99))
 
    
    
    
'''
run:
    
0
1
3
3
3
-4
 
'''

 



answered Apr 23, 2021 by avibootz

Related questions

...