Home > other >  Convert a value as a result of google colab which has e to a real value?
Convert a value as a result of google colab which has e to a real value?

Time:02-11

I have something like 3.34985746e-06 as a result of a calculation in colab. How can I convert this to a more readable value?

CodePudding user response:

If you're just confused why it's represented as a string you can get it back to a float using float().

In [11]: val = '{:e}'.format(12312312312123)

In [12]: val
Out[12]: '1.231231e 13'

In [13]: float(val)
Out[13]: 12312310000000.0

If instead you want fewer decimals displayed you can format your scientific notation with {:.Ne} where N is the number of decimals places:

In [14]: '{:.3e}'.format(0.00000334985756)
Out[14]: '3.350e-06'

Notice that the above also takes care of rounding for you.

  • Related