Search code examples
lua

How to check if a number have integer representation


How to check if a number have integer representation

number can be a float or double


Solution

  • In Lua 5.3+, use math.tointeger:

    math.tointeger (x)

    If the value x is convertible to an integer, returns that integer. Otherwise, returns nil.