使用 numpy 或 python 的标准库,或者。我怎样才能把一个有几个小数位的值截断到 4 个小数位?我只想将 float 与其前 4 个小数点进行比较。
请您参考如下方法:
圆(a_float,4)
>>> help(round)
Help on built-in function round in module __builtin__:
round(...)
round(number[, ndigits]) -> floating point number
Round a number to a given precision in decimal digits (default 0 digits).
This always returns a floating point number. Precision may be negative.
>>>
