从5.3开始,Lua format.string不能将float格式化为十进制(%d) [英] Lua format.string can't format float as decimal (%d) as of 5.3
本文介绍了从5.3开始,Lua format.string不能将float格式化为十进制(%d)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我最近从Lua 5.2.3升级到5.3.1,但是我发现执行string.format
的所有脚本如果尝试使用%d
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.
推荐答案
在Lua 5.3中,number
类型具有两个子类型integer
和float
.
In Lua 5.3, the number
type has two subtypes, integer
and float
.
选项
A
,a
,E
,e
,f
,G
和g
都期望数字作为参数.选项c
,d
,i
,o
,u
,X
和x
期望为整数.
Options
A
,a
,E
,e
,f
,G
, andg
all expect a number as argument. Optionsc
,d
,i
,o
,u
,X
, andx
expect an integer.
这篇关于从5.3开始,Lua format.string不能将float格式化为十进制(%d)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文