Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 917
Puddler Avatar asked Jul 23 '15 02:07

Puddler


1 Answers

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.

like image 88
Yu Hao Avatar answered Nov 03 '22 02:11

Yu Hao