Equality for floating point numbers
Syntax
$e1.isFloatEqual($e2, $precision)
Description
Compares two floating point numbers with each other, when rounding to precision
digits.
The expression is equivalent to
$e1.round($precision) == $e2.round($precision)
Parameters
Name | Type | Description | Mandatory | Default |
---|---|---|---|---|
e1 | Number | A floating point number to be compared with e2 . |
yes | |
e2 | Number | A floating point number to be compared to e1 . |
yes | |
precision | Number | A number that specifies how many decimal places to include. | yes |
Return value
Type: Boolean
true
, if the two float numbers are equal to the specified precision.
Examples
Comparison with 2 decimal places
3.1314.isFloatEqual(3.1315, 2)
Output: true
The numbers are equal because they are compared only up to the second decimal place.
Comparison with 5 decimal places
3.1314.isFloatEqual(3.1315, 5)
Output: false