0

Check out this code:

>>> print "var: %g" % 3.12345678
var: 3.12346
>>> print "var: %G" % 3.12345678
var: 3.12346
>>> print "var: %e" % 3.12345678
var: 3.123457e+00
>>> print "var: %E" % 3.123456
var: 3.123457E+00

Why don't all the digits get displayed?

Why does the 6 get dropped from scientific notation?

2 Answers 2

1

Use %.nf where n is the number of sig-figs

print 'var: %.10f' % 3.12345678
# outputs: "var: 3.1234567800"

print 'var: %.10E' % 3.12345678
# outputs: "var: 3.1234567800E+00"

print 'var:', 3.12345678
# outputs: "var: 3.12345678"
Sign up to request clarification or add additional context in comments.

Comments

0

see: http://docs.python.org/2/library/stdtypes.html the default precision of %g and %G is 6, so it only output 6 digits (truncated).

for exponential format, the default precision is 6 digits AFTER decimal point, and it is rounded (to 3.123457)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.