Reputation: 83
I'm doing some calculation with python. But I troubling with decimal numbers. my code is like:
from decimal import *
x = 0.0000001582
y = 0.00000020
z = 1000
a = 0.000000100
b = (x+y)/z
result = x + b
print result
My results comes like this 1.585582e-07
.
I want simple decimal number up to 10 digits. How can I do that?
Upvotes: 0
Views: 867
Reputation: 133
Based on python documents you can use getcontext()
it will be like this:
from decimal import getcontext
#Here you set decimal numbers limit(in your case 10 digits):
getcontext().prec = 10
Upvotes: 0
Reputation: 810
Try this hope works for you: https://repl.it/ODuB
from decimal import *
x = 0.0000001582
y = 0.00000020
z = 1000
a = 0.000000100
b = (x+y)/z
result = x + b
print format(result, '.10f')
Upvotes: 0
Reputation: 149
You could do something like
print '{0:.10f}'.format(variable)
Where the 10f is the digits you want to go and variable is what you want to print
Upvotes: 0