Meaning#

Lua numbers normally use double. Do not blindly convert integer identifiers wider than 53 bits to number: precision can be lost. tonumber can return nil.

Example#

LUA
local amount = tonumber("12")
if amount ~= nil then
  amount = math.max(0, amount)
end

What happens: amount = 12; math.max leaves it unchanged because 12 is greater than zero.

This fragment does not print or write a log message. The values shown are the expected results of the example.

Methods and related calls#

Function Returns Purpose
math.abs number Returns the absolute value.
math.asin number Returns the arcsine in radians.
math.atan2 number Returns a quadrant-aware angle in radians from y and x.
math.ceil number Rounds toward the smallest integer greater than or equal to the value.
math.cos number Returns the cosine of an angle in radians.
math.deg number Converts radians to degrees.
math.floor number Rounds toward the largest integer less than or equal to the value.
math.max number Returns the largest numeric argument.
math.min number Returns the smallest numeric argument.
math.rad number Converts degrees to radians.
math.random number Returns a pseudorandom value: [0,1) without bounds, an integer from 1 with one bound, or an integer between two bounds.
math.sin number Returns the sine of an angle in radians.
math.sqrt number Returns the square root.