Lua format.string 自 5.3 起无法将浮点数格式化为十进制 (%d)
Lua format.string can't format float as decimal (%d) as of 5.3
我最近从 Lua 5.2.3 升级到 5.3.1,但我注意到我所有执行 string.format
的脚本在尝试使用 float
格式化 float
时开始失败=15=]
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
这是设计使然吗?我似乎无法在任何地方找到记录的更改。
在Lua 5.3中,number
类型有两个子类型,integer
和float
。
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.
我最近从 Lua 5.2.3 升级到 5.3.1,但我注意到我所有执行 string.format
的脚本在尝试使用 float
格式化 float
时开始失败=15=]
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
这是设计使然吗?我似乎无法在任何地方找到记录的更改。
在Lua 5.3中,number
类型有两个子类型,integer
和float
。
Options
A
,a
,E
,e
,f
,G
, andg
all expect a number as argument. Optionsc
,d
,i
,o
,u
,X
, andx
expect an integer.