September 20, 2022


Number in Lua is a double precision floating-point number (or double for short). For example: 5.1, 9.12761656, -1927.52.

In Lua, the range of numbers can be -1.7 × 10308 to 1.7 × 10308 (about 15 digits, positive or negative).

Signed and unsigned: the sign of a number indicates whether it is positive or negative. Signed numbers can be positive or negative, but unsigned numbers cannot be negative. In Lua, -0 is different from 0.

When working with floating-point numbers in Lua, note the following:
To round (round) a number to the nearest integer, use math floor(x + 0.5)。

Type introspection: you can use type (x) to determine whether a value is a number. When it is a number, both will return the string number.