python 浮点数转整数溢出

from decimal import Decimal, getcontext

# getcontext().prec设置有效数字的个数
getcontext().prec = 2
# 四舍五入,保留几位小数
a = str(Decimal(0.5811966).quantize(Decimal('0.00')) * 100) + '%'
print('a = ', a)
posted @ 2022-11-09 12:06  黑山老道  阅读(27)  评论(0编辑  收藏  举报