How to set precision format for decimal value in Python

1 Answer

0 votes
import decimal
 
d = decimal.Decimal(1.1)     

print('{:.1}'.format(d))     
print('{:.2}'.format(d))     
print('{:.3}'.format(d))     
print('{:.28}'.format(d))



'''
run:

1 
1.1
1.10
1.100000000000000088817841970

'''

 



answered Jun 7, 2019 by avibootz

Related questions

1 answer 171 views
1 answer 186 views
1 answer 201 views
1 answer 174 views
174 views asked Sep 5, 2019 by avibootz
1 answer 117 views
...