Skip to main content
tonumber(v) converts v to a number. Numeric strings like "42" or "3.14" are parsed. Numbers pass through unchanged.

Signature

Example

Read a timeout value from an environment variable and use it as a number in a command:

Notes

  • The string must be a valid decimal number. Non-numeric strings produce an error.
  • For integers in non-decimal bases (hex, binary), use parseint instead.
  • tonumber is most useful when a numeric value comes from an environment variable or a string expression.