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

51,826 answers

573 users

How to round a number to 2 decimal places in Python

4 Answers

0 votes
print("{:.2f}".format(5.5691)) 

print("{:.2f}".format(5.4823)) 


     
     
'''
run:
 
5.57
5.48
 
'''

 



answered Jul 15, 2022 by avibootz
0 votes
print(round(5.5691, 2))  
 
print(round(5.4823, 2)) 
 


     
     
'''
run:
 
5.57
5.48
 
'''

 



answered Jul 15, 2022 by avibootz
0 votes
import math
 
def round_down_float_to_2_decimal_places(num):
    return math.floor(num * 100) / 100
     
print(round_down_float_to_2_decimal_places(5.5691))  
 
print(round_down_float_to_2_decimal_places(5.4823)) 



     
     
'''
run:
 
5.56
5.48
 
'''

 



answered Jul 15, 2022 by avibootz
0 votes
import math
 
def round_up_float_to_2_decimal_places(num):
    return math.ceil(num * 100) / 100
     
print(round_up_float_to_2_decimal_places(5.5691))  
 
print(round_up_float_to_2_decimal_places(5.4123)) 
 



     
     
'''
run:
 
5.57
5.42
 
'''

 



answered Jul 15, 2022 by avibootz

Related questions

1 answer 139 views
1 answer 226 views
3 answers 148 views
2 answers 119 views
1 answer 82 views
3 answers 154 views
...