--- title: number - Numbers summary: 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. section: reference kind: guide status: reference updated: 2026-10-26 tags: ["API","X4"] sources: ["https://wiki.egosoft.com/X4%20Foundations%20Wiki/Modding%20Support/","https://www.lua.org/manual/5.1/manual.html","https://luajit.org/ext_ffi_api.html"] --- ## 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](wiki:api-standard-math-abs-e3c883a9) | [`number`](wiki:type-number) | Returns the absolute value. | | [math.asin](wiki:api-standard-math-asin-0ff09b19) | [`number`](wiki:type-number) | Returns the arcsine in radians. | | [math.atan2](wiki:api-standard-math-atan2-b4fe910e) | [`number`](wiki:type-number) | Returns a quadrant-aware angle in radians from y and x. | | [math.ceil](wiki:api-standard-math-ceil-bb032e94) | [`number`](wiki:type-number) | Rounds toward the smallest integer greater than or equal to the value. | | [math.cos](wiki:api-standard-math-cos-4a293dba) | [`number`](wiki:type-number) | Returns the cosine of an angle in radians. | | [math.deg](wiki:api-standard-math-deg-6ef5ae35) | [`number`](wiki:type-number) | Converts radians to degrees. | | [math.floor](wiki:api-standard-math-floor-5776363e) | [`number`](wiki:type-number) | Rounds toward the largest integer less than or equal to the value. | | [math.max](wiki:api-standard-math-max-4dc62550) | [`number`](wiki:type-number) | Returns the largest numeric argument. | | [math.min](wiki:api-standard-math-min-9b2931d6) | [`number`](wiki:type-number) | Returns the smallest numeric argument. | | [math.rad](wiki:api-standard-math-rad-1bbc48b1) | [`number`](wiki:type-number) | Converts degrees to radians. | | [math.random](wiki:api-standard-math-random-d0204929) | [`number`](wiki:type-number) | Returns a pseudorandom value: [0,1) without bounds, an integer from 1 with one bound, or an integer between two bounds. | | [math.sin](wiki:api-standard-math-sin-cd360f65) | [`number`](wiki:type-number) | Returns the sine of an angle in radians. | | [math.sqrt](wiki:api-standard-math-sqrt-b3c6fba6) | [`number`](wiki:type-number) | Returns the square root. |