【问题标题】:How to round number to 3 decimals max?How to round number to 3 decimals max?
【发布时间】:2022-12-02 03:31:48
【问题描述】:

I am trying to round up 5.9999998 to 5.999.

But I have a problem, If I do round(number) it'll round it up to 6. How can I round a number like this to max 3 decimals?

【问题讨论】:

标签: python numbers


【解决方案1】:

You can use this:

number = 5.999999998
new_number = int(number * 1e3) / 1e3

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-12-02
    • 2022-12-02
    • 2022-12-02
    • 2021-07-14
    • 2011-04-06
    • 2022-12-16
    • 2022-12-27
    • 2022-12-01
    相关资源
    最近更新 更多