简体   繁体   中英

How to round down two significant figures in python?

提示:本站收集StackOverFlow近2千万问答,支持中英文搜索,鼠标放在语句上弹窗显示对应的参考中文或英文, 本站还提供   中文简体   中文繁体   中英对照 版本,有任何建议请联系yoyou2525@163.com。

I've seen the solutions around but they mostly round up to two significant figures and not down

I have tried these few methods

import math
v = 0.000129
math.floor(v*100)/100

-output-
0.0    

or

v = 0.000129
from decimal import Decimal
float(f"{Decimal(f'{v:.2g}'):f}")

-output-
0.00013

As you can see, I want to have two significant figures but do not want them rounded up. Decimal works to give the two sig figs but it rounds up while math just simply gives me 0.

ie a few to test

1999 -> 1900
29901 - > 29000
0.0199 -> 0.019

Thanks!

No answers.You can refer to the related questions on the right.
暂无
暂无

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-2022 STACKOOM.COM