我正在尝试通过在液体中使用舍入来舍入小数值。但是圆形没有用

I'm trying to round the decimal values by using round in liquid. But round didn't work

我已尝试使用文档中提到的舍入对浮点值进行舍入 (https://shopify.github.io/liquid/filters/round/)。

这是代码

{% assign my_integer = 0.346257 | times: 100 %}
<span>{{ my_integer | round: 2 }} %</span>

但结果我喜欢

34.625699999999995 %

我正在尝试显示 35%。我不知道为什么回合不起作用。

目前如下:

{% assign my_integer = 0.346257 | times: 100 %} <span>{{ my_integer | round: 2 }} %</span>

Returns 对我来说:34.63 % 我不知道你是怎么得到 34.625699999999995 % 的。

如果你只想得到 35% 你应该把它写成 | round 不需要后面的 2,因为它表示小数点后多少个数字将开始舍入:

{% assign my_integer = 0.346257 | times: 100 %} <span>{{ my_integer | round }} %</span>