Reputation: 11
I'm trying to set 3 digits after point but it returns me 0.03 instead of 0.030 Here's the code:
import decimal
decimal.getcontext().prec = 3
a = float(input())
qur = []
x = 2
b = a / 100
while x < 12:
qur.append(b)
b = (a * x) / 100
x += 1
print(" ".join([str(i) for i in qur]))
Upvotes: 0
Views: 227
Reputation: 42758
You are not using decimal
s, so setting their precision has no effect. For output with a fixed number of digits, use string formatting:
print(" ".join('{0:.3f}'.format(i) for i in qur))
Upvotes: 2