Choose where you’d like to start

toNumber

Overview

The toLong function takes an expression as an argument, and returns a number.

Note:

  • Decimals when subjected to the toNumber function will lose their fraction parts. Use toDecimal instead.
  • If a piece of text has alphanumeric data(say, 1000abc) in it, then toNumber function will throw an error message.

Return Type

  • NUMBER

Syntax

<variable> = <expression>.toNumber();

(OR)

<variable> = toNumber(<expression>);

(OR)

<variable> = <expression>.toLong();

(OR)

<variable> = toLong(<expression>);

where,

ParameterData typeDescription
<variable>NUMBERVariable which will contain the converted number.
<expression>NUMBER/DECIMAL/DATE-TIME/TEXT

The expression which will resolve to a number.

Note:

  • Date-time values will be converted into their equivalent number of milliseconds starting from '31-Dec-1969 16:00:00' (which is equivalent to 0).
    For instance, '31-Dec-1969 16:00:01'.toNumber() will yield 1000 and '31-Dec-1969 15:59:59'.toNumber() will yield -1000 and so on.
  • Decimals will be truncated off their fraction parts.
  • Empty texts will throw an error during runtime.

Examples

 decimal = 123.25;
 info  decimal.toNumber(); // Converts the decimal into a number and returns 123
 num_text = "1234";
 info  num_text.toNumber(); // Returns 1234
 alpha_text = "134A123B";
 info  alpha_text.toNumber(); // Returns error

Get Started Now

Execute