2

Is it possible for force ipython to output in scientific notation, or set the threshold at which it switches to scientific notation?

For example,

In [26]: 1000000000000

Out[26]: 1000000000000

But I want:

In [26]: 1000000000000

Out[26]: 1e12

Can I do this? I saw an old answer to this from years ago but it does not appear to be working anymore.

Subbu VidyaSekar
  • 2,503
  • 3
  • 21
  • 39
ricitron
  • 151
  • 1
  • 9
  • 3
    Does this answer your question? [set ipython's default scientific notation threshold](https://stackoverflow.com/questions/16866761/set-ipythons-default-scientific-notation-threshold) – Nagabhushan S N Aug 14 '20 at 01:45
  • 1
    There is no threshold at which IPython will print *ints* in scientific notation. Floats, sure, but not ints. Printing ints in scientific notation would be ambiguous, making them look like floats. – user2357112 Aug 14 '20 at 01:45
  • @NagabhushanSN that doesn't answer the question. The solution no longer works. In ipython if I type %precision %.3e and then 1000000000000. it still outputs as 1000000000000.0 – ricitron Aug 14 '20 at 02:04
  • @user2357112supportsMonica I find the same behavior when trying to output 100000000.0 – ricitron Aug 14 '20 at 02:05

1 Answers1

2

just you do formatting like this:

print("{:e}".format(12300000))

output:

1.230000e+07
Subbu VidyaSekar
  • 2,503
  • 3
  • 21
  • 39