Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

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?

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading