Home > front end >  Including lesser number of decimal points from the list written in scientific notation
Including lesser number of decimal points from the list written in scientific notation

Time:11-07

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.

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

CodePudding user response:

Try this:

list_1 = [float('{:0.4e}'.format(i)) for i in list_1]
  • Related