简体   繁体   中英

Control floating point precision in python

I have a number in python like 2.75960192084e-05. I want to display it with less number of numbers after decimal point like 2.759e-05. Note the exponent should remain displayed. Is that possible ?

the Format Specification Mini-Language allows you do do that with:

f = 2.75960192084e-05
print('{:9.3e}'.format(f))  # 2.760e-05

...it will round though.

the 9 means that 9 is the minimal witdh of the resulting string; with 3 places behind the decimal point in e xponent notation.

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