简体   繁体   中英

Is there a way to convert scientific notation to just the first few decimal places in Python?

I have a list of 1111 values in scientific notation. Here are a few examples:

6.042968853864891e-12, 6.042894605467602e-12, 6.042777396826408e-12, 6.042616263531836e-12, 6.042410211830538e-12, 6.042158216350682e-12, 

Is there a way I can convert this to just a list of 6.0429885, 6.04289460, 6.04277739, 6.04261626, 6.04241021, 6.04215821 (8 decimal places)? I don't want the scientific notation part (e-12).

I am ultimately trying to plot longitude on the x axis, latitude on the y-axis and have the points different sizes or colors based on density values (the density values are the numbers above in scientific notation). Here is a plot I have of just the longitude and latitude. I want to have this and each point be varying size depending on what the density is at that location.

在此处输入图片说明

Seems like you just need to multipy these numbers by 1e12 then round to 8 decimal places, right?

a = [6.042968853864891e-12, 6.042894605467602e-12, 6.042777396826408e-12, 6.042616263531836e-12, 6.042410211830538e-12, 6.042158216350682e-12, 
]

b = [round(i*1e12,8) for i in a]

# if you want to scale your plot, then you shouldn't need to change the list itself, rather do this to your plot:

# if you have an ax, do:
ax.set_ylim([0,1e-11]) 
# this will give you a fixed y axis limit between 0 and 1e-11.


The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM