The Number is a data type used for storing numbers. Number internally is stored as a Java Double type (that could be important for very few extreme scenarios).

You can use comparison operators to compare Numbers with each other, while arithmetic operators can be used to perform math operations on Numbers.

Here are some examples of Numbers:

  • 6
  • 9999
  • 1.25
  • 1.999999

Unlike Strings, Numbers are written without using any quotation marks (i.e. 125.5). It is important to remember that a String containing a Number does NOT have a 'number' data type, i.e. "1.25" is a String, while 1.25 is a Number. To convert between these two types, use one of the two methods: (2.15).toString() to convert Number into String, and "1.25".toNumber() to convert String into Number.

List of number methods

The following table contains all of the Number methods.

To use a method on a fractional number, you need to enclose the Number within parentheses. For more details see the table and examples below.

MethodDescription
toString()Converts a Number to a String.
round()Rounds a Number to the closest integer number (0.5 is rounded UP).
floor()Returns only the integer part without the fractional part.
ceiling()Rounds a Number to the nearest higher integer Number.
abs()Returns the absolute value of the Number.
toFixed(digits)Rounds a Number to a fractional Number with specified digits after the decimal point.

toString()

Renders Number as a String. For fractional Numbers, will round a Number to two digits after the decimal point, e.g. "1.26". For integer Numbers, the result won't contain a fractional part, e.g. 9999. This method returns a String.

9999.toString()
//Result:
"9999"

(1.2555).toString()
//Result:
"1.26"

round()

Rounds a Number to the closest integer Number (0.5 is rounded up). This method returns a Number.

10.round() //Result: 10
(10.1).round() // Result: 10
(10.49).round() // Result: 10
(10.499).round() // Result: 10
(10.5).round() // Result: 11
(10.99).round() // Result: 11

floor()

Drops any digits after the decimal point, and returns only the integer part. This method returns a Number.

10.floor() // Result: 10
(10.1).floor() // Result: 10
(10.5).floor() // Result: 10
(10.99).floor() // Result: 10

ceiling()

Rounds a Number to the nearest higher integer Number. If the Number is an integer, it will return the same Number. This method returns a Number.

10.ceiling() // Result: 10
(10.001).ceiling() // Result: 11
(10.5).ceiling() // Result: 11
(10.99).ceiling() // Result: 11

abs()

Returns the absolute value of the Number (a distance from zero). This method returns a Number.

10.abs() // Result: 10
(0.5).abs() // Result: 0.5
(-10).abs() // Result: 10
(-0.5).abs() // Result: 0.5

toFixed(digits)

Rounds a Number to a fractional Number with specified digits after the decimal point. This method returns a String.

10.toFixed(2) //Result: "10.00"
(10.55).toFixed(1) // Result: "10.6"
(10.1).toFixed(2) // Result: "10.10"

What’s Next

Learn more about Expression language and its methods & APIs: