从5.3开始,Lua format.string不能将float格式化为十进制(%d) [英] Lua format.string can't format float as decimal (%d) as of 5.3

查看:368
本文介绍了从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类型具有两个子类型integerfloat.

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

来自 string.format

选项AaEefGg都期望数字作为参数.选项cdiouXx期望为整数.

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.

这篇关于从5.3开始,Lua format.string不能将float格式化为十进制(%d)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆