954,510 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Small decimal number using "decimal" module

Hello all

I'm having a few issues with a Python program in that I am performing decimal calculations on and most values come up as desired, however every so often, when there is a very small decimal, the number is represented like "6.80E-7" rather than the desired "0.000000680". Here's a snippet of the code that I'm using:

import decimal
decimal.getcontext().prec = 9
now = "230.939809280"
then = "230.939808600"
print str(decimal.Decimal(now) - decimal.Decimal(then))


This gives the following response:

6.80E-7


Does anyone know of a way for me to display this output as "0.000000680" instead?

Any help would be most appreciated :)

Simplified
Light Poster
35 posts since Aug 2010
Reputation Points: 10
Solved Threads: 1
 
decimal.getcontext().prec = 9
now = "230.939809280"
then = "230.939808600"
print "%.9f" % (decimal.Decimal(now) - decimal.Decimal(then))
# -> 0.000000680
pyTony
pyMod
Moderator
5,359 posts since Apr 2010
Reputation Points: 782
Solved Threads: 852
 

That's absolutely perfect, thanks very much indeed tonyjv :)

Simplified
Light Poster
35 posts since Aug 2010
Reputation Points: 10
Solved Threads: 1
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: