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

Including lesser number of decimal points from the list written in scientific notation

Suppose you have a list of values as given bellow:
list_1 = [1.3846881856127702e-05, 8.253583720918556e-07, 5.099125943708316e-08, 3.1775544417911306e-09, 1.9845003418339502e-10]

I would like to know whether there is a way to obtain the same list with fewer decimal places? Something like 4.
I know that there is an option of writing it as,

list_1=[ '%.2f' % elem for elem in list_1 ] but since the original values are much smaller, then it will only display zeros.

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

What I would like to have is something like:
list_1 = [1.3846e-05 , 8.2535e-07....]

>Solution :

Try this:

list_1 = [float('{:0.4e}'.format(i)) for i in list_1]
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