【发布时间】:2014-09-29 03:13:15
【问题描述】:
此脚本在程序中显示一个值:
string.format("%d", math.floor(self:value())) -- Where self:value() is a number like 4.1256913947
此脚本采用相同的值并将其打印到我的控制台。
math.floor(value) -- Where value is the same number as self:value() was...it's just being sent to another function as well
问题是显示值和控制台打印的值不匹配。这种情况很少发生,而且很少发生,但是当用户输入的数据略微超过整数(即 4.0029893417)或其他任何情况时,它会无缘无故地将其降至 3。我试过math.ceil,但是当它关闭时会发生相反的效果(即4.89898989)它打印5但显示4。有没有办法让它完全截断数字?从而正确显示并正确打印?
注意:该值是不可更改的,因为有时这些额外的小数需要存在并在其他地方/功能中相应地处理。
谢谢:)
【问题讨论】:
-
问题可能出在其他地方。提供a Minimal, Complete, and Verifiable example。
标签: string math lua truncate floor