'Print decimal numbers with python
I have some troubles when creating a cost report, which should contain costs with decimal points.
Bellow is a list with example costs. When I print the cost to the console (or export to a file), some of the values do not appear as expected.
import decimal
li = [
{
"cost": 0E-10
},
{
"cost": 0.0000400000
},
{
"cost": 1.000*0.00005
},
]
for c in li:
print(f"Cost: {round(decimal.Decimal(c['cost']), 10)}")
# Cost: 0E-10
# Cost: 0.0000400000
# Cost: 0.0000500000
As seen in the output, the first value is displayed as 0E-10 instead of 0.
How could I achieve to get all the time decimal numbers printed?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
