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

51,817 answers

573 users

How to represent decimal values with decimal class in Python

1 Answer

0 votes
import decimal

fmt = '{0:<10} {1:<10}'

print(fmt.format(12, decimal.Decimal(12)))

print(fmt.format('3.14159', decimal.Decimal('3.14159')))

print(fmt.format(repr(0.3), decimal.Decimal(str(0.3))))

print('{:<0.23} {:<19}'.format(0.3, str(decimal.Decimal.from_float(0.3))[:19]))




'''
run:

12         12
3.14159    3.14159
0.3        0.3
0.29999999999999998889777 0.29999999999999998
 
'''

 



answered Jun 7, 2019 by avibootz

Related questions

1 answer 89 views
1 answer 153 views
2 answers 186 views
1 answer 161 views
1 answer 121 views
1 answer 118 views
...