7

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.

Yu Hao
  • 119,891
  • 44
  • 235
  • 294
Puddler
  • 2,619
  • 2
  • 17
  • 26

1 Answers1

9

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.

Yu Hao
  • 119,891
  • 44
  • 235
  • 294
  • 1
    The design of Lua 5.3 isn't clean in many ways, f.e. math.tointeger (while tostring & tonumber is in _G), math.type (just to differentiate integer and float), math.ult (needless?), etc. – Youka Jul 23 '15 at 02:32
  • Thanks for that, I missed that completely (even though it was the obvious place to look). I think I was expecting a more explicit note to say it had been changed from 5.2->5.3 like in [here](http://www.lua.org/manual/5.3/manual.html#8) – Puddler Jul 23 '15 at 03:07