众力资讯网

Python中四舍五入的方法你真的会吗❗❗❗

Python中四舍五入的方法: ~ [一R]使用 round round() 把 number(通常是浮点数) 按一定规则(Python3)进行四舍五入的。 1⃣️ndigits 不为 0 的情况 (具体详见笔记) 2⃣️ ndigits 为 0 或 None 的情况 (具体详见笔记) ~ [二R]使用 Decimal 这种方法有个前提,那就是必须先把小数转换成字符串,这样才可以精确地表示浮点数。 ~