84669 人が学習中
152542 人が学習中
20005 人が学習中
5487 人が学習中
7821 人が学習中
359900 人が学習中
3350 人が学習中
180660 人が学習中
48569 人が学習中
18603 人が学習中
40936 人が学習中
1549 人が学習中
1183 人が学習中
32909 人が学習中
[-0.32695389161796801, -0.31471406408825409, -0.31475407980700348] の各要素に対して、round(round(-0.3269538916179680 1,3) ,2 ) ちなみに、[-0.33000000000000002, -0.32000000000000001, -0.32000000000000001] ですが、取得したいのは [-0.33, -0.32, -0.32] です、ありがとう
认证高级PHP讲师
在使用Python处理精度很重要的浮点数时,建议使用内置的Decimal库:
from decimal import Decimal a = Decimal('1.0231212121') a = round(a,3) # Decimal('1.023')
如果只是要求看起来“精确”,那么也可以用字符串的format方法
'{:.2f}'.format(1.0231212121) # '1.02'
在使用Python处理精度很重要的浮点数时,建议使用内置的Decimal库:
如果只是要求看起来“精确”,那么也可以用字符串的format方法