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 160 views
1 answer 171 views
1 answer 192 views
1 answer 159 views
159 views asked Sep 5, 2019 by avibootz
1 answer 103 views
...