Lua format.string can't format float as decimal (%d) as of 5.3

流过昼夜 提交于 2019-12-07 00:07:34

问题


I recently upgraded from Lua 5.2.3 to 5.3.1 but I noticed all my scripts that perform a string.format started failing if it tried to format a float using %d

local anExampleString = string.format("Sample Number: %d",10.100000001) -- Fails on 5.3.1, works on 5.2.3
local aWorkingString  = string.format("Sample Number: %.0f",10.100000001) -- Works on 5.3.1

Is this by design? I can't seem to find the change documented anywhere.


回答1:


In Lua 5.3, the number type has two subtypes, integer and float.

From string.format

Options A, a, E, e, f, G, and g all expect a number as argument. Options c, d, i, o, u, X, and x expect an integer.



来源:https://stackoverflow.com/questions/31577104/lua-format-string-cant-format-float-as-decimal-d-as-of-5-3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!