0

Are there any means by which one could tell Python 2.x/3.x to always use 3 digits for the exponent when printing a float (==IEEE754 double precision) in scientific format using the "E" format specifier (or another one)?

  • Does [this](http://stackoverflow.com/questions/8345795/force-python-to-not-output-a-float-in-standard-form-scientific-notation-expo) cover what you need? I'm the one who tagged this as a duplicate. – Prune Apr 18 '16 at 21:07
  • @Prune: No, because they want to format the exponent, not the mantissa. – Ignacio Vazquez-Abrams Apr 18 '16 at 21:08
  • The answer from panda-34 parses the output string and extracts the exponent (as well as the other parts of the representation). From here, OP can build any desired format from the parts -- and the given answers provide most of those parts. – Prune Apr 18 '16 at 21:16
  • @Prune: thanks for bringing a workaround for the problem to my attention. – derSchorsch Apr 19 '16 at 07:09
  • I don't see the "answer from panda-34," @Prune – Ana Nimbus Oct 10 '18 at 00:42
  • That answer seems to have been deleted in the 2.5 years intervening. – Prune Oct 10 '18 at 15:35

1 Answers1

0

Unfortunately no, the width and precision of the format specifier only affect presentation of the mantissa. You will need to post-process the string if you want to affect the exponent.

Ignacio Vazquez-Abrams
  • 776,304
  • 153
  • 1,341
  • 1,358