Numeric functions
decimal()β
Round the given number at the given scale using the given rounding mode. If no rounding mode is passed in, it uses HALF_EVEN
as default.
- parameters:
n
: numberscale
: number- (optional)
mode
: string - one ofUP, DOWN, CEILING, FLOOR, HALF_UP, HALF_DOWN, HALF_EVEN, UNNECESSARY
(default:HALF_EVEN
)
- result: number
decimal(1/3, 2)
// .33
decimal(1.5, 0)
// 2
decimal(2.5, 0, "half_up")
// 3
floor()β
- parameters:
n
: number
- result: number
floor(1.5)
// 1
floor(-1.5)
// -2
floor(-1.56, 1)
// -1.6
ceiling()β
Round the given number at the given scale using the ceiling rounding mode.
- parameters:
n
: number -(optional)scale
: number (default:0
)
- result: number
ceiling(1.5)
// 2
ceiling(-1.5)
// -1
ceiling(-1.56, 1)
// -1.5
round up()β
Round the given number at the given scale using the round-up rounding mode.
- parameters:
n
: number- (optional)
scale
: number (default:0
)
- result: number
round up(5.5)
// 6
round up(-5.5)
// -6
round up(1.121, 2)
// 1.13
round up(-1.126, 2)
// -1.13
round down()β
Round the given number at the given scale using the round-down rounding mode.
- parameters:
n
: number- (optional)
scale
: number (default:0
)
- result: number
round down(5.5)
// 5
round down (-5.5)
// -5
round down (1.121, 2)
// 1.12
round down (-1.126, 2)
// -1.12
round half up()β
Round the given number at the given scale using the round-half-up rounding mode.
- parameters:
n
: number- (optional)
scale
: number (default:0
)
- result: number
round half up(5.5)
// 6
round half up(-5.5)
// -6
round half up(1.121, 2)
// 1.12
round half up(-1.126, 2)
// -1.13
round half down()β
Round the given number at the given scale using the round-half-down rounding mode.
-parameters:
n
: number -(optional)scale
: number (default:0
)- result: number
round half down (5.5)
// 5
round half down (-5.5)
// -5
round half down (1.121, 2)
// 1.12
round half down (-1.126, 2)
// -1.13
abs()β
Returns the absolute value of the given numeric value.
- parameters:
number
: number
- result: number
abs(10)
// 10
abs(-10)
// 10
modulo()β
Returns the remainder of the division of dividend by divisor.
- parameters:
dividend
: numberdivisor
: number
- result: number
modulo(12, 5)
// 2
sqrt()β
Returns the square root.
- parameters:
number
: number
- result: number
sqrt(16)
// 4
log()β
Returns the natural logarithm (base e) of the number.
- parameters:
number
: number
- result: number
log(10)
// 2.302585092994046
exp()β
Returns the Eulerβs number e raised to the power of number .
- parameters:
number
: number
- result: number
exp(5)
// 148.4131591025766
odd()β
Returns true
if the given numeric value is odd. Otherwise, it returns false
.
- parameters:
number
: number
- result: boolean
odd(5)
// true
odd(2)
// false
even()β
Returns true
if the given numeric value is even. Otherwise, it returns false
.
- parameters:
number
: number
- result: boolean
even(5)
// false
even(2)
// true