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 :)

decimal.getcontext().prec = 9
now = "230.939809280"
then = "230.939808600"
print "%.9f" % (decimal.Decimal(now) - decimal.Decimal(then))
# -> 0.000000680

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.