如何计算一定数量的小数位数值?

Chr*_*ris 1 python floating-accuracy

使用numpy或python的标准库,或者.如何获取具有多个小数位的值并将其截断为4位小数?我只想将浮点数与前4个小数点进行比较.

Joh*_*hin 6

圆(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.

>>>
Run Code Online (Sandbox Code Playgroud)