You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
> A list of JavaScript quirks which should be kept in mind when writing implementations.
4
+
5
+
## Rounding
6
+
7
+
1. The JavaScript standard ([ECMA-262][ecma-262-math-round]) defines the behavior of `Math.round` such that "ties" (e.g., `1.5` and `-1.5`) are rounded toward `+infinity`.
8
+
9
+
```javascript
10
+
var x =Math.round( 1.5 );
11
+
// returns 2.0
12
+
13
+
x =Math.round( -1.5 );
14
+
// returns -1.0
15
+
```
16
+
17
+
This behavior is relatively uncommon among languages implementing a round operation for floating-point numbers and appears to have originated by following [Java][java-math-round].
18
+
19
+
When implementing lower-level math functions which may require rounding, exercise caution when considering whether the built-in rounding behavior is appropriate and ensure that bias is not introduced in computed results.
0 commit comments