如何控制reportlab表中的浮点数精度?

问题描述 投票:0回答:1

我正在使用带有Python 3.7的reportlab创建一个表。我想知道是否有办法改变浮点数十进制精度。

例如,现在一个单元格中的浮点数是4.33333333。我想使用表格样式选项将其更改为4.33。

将浮点数改为2位数的字符串不是一个选项,因为我需要用这些数字来计算。

python numbers precision reportlab
1个回答
-1
投票

我不熟悉reportlab但是在python中你可以使用这样的字符串格式:

print('{0:.2f}'.format(4.33333333))
>> 4.33

print('{0:.4f}'.format(4.33333333))
>> 4.3333
© www.soinside.com 2019 - 2024. All rights reserved.