Skip to content

Commit 2e7fbc4

Browse files
authored
Update round fraction example
In the particular example with multiplying and dividing by 100 there is no mistake. However using `Math.round` instead of `Math.floor` would be better. If it was a number `1.23567`, the rounded result would be `1.24`. But with the current `Math.floor` we still get `1.23` which is incorrect.
1 parent c0b8c71 commit 2e7fbc4

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

1-js/05-data-types/02-number/article.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ alert( num.toString(2) ); // 11111111
151151
```js run
152152
let num = 1.23456;
153153
154-
alert( Math.floor(num * 100) / 100 ); // 1.23456 -> 123.456 -> 123 -> 1.23
154+
alert( Math.round(num * 100) / 100 ); // 1.23456 -> 123.456 -> 123 -> 1.23
155155
```
156156

157157
2. Метод [toFixed(n)](https://developer.mozilla.org/ru/docs/Web/JavaScript/Reference/Global_Objects/Number/toFixed) округляет число до `n` знаков после запятой и возвращает строковое представление результата.

0 commit comments

Comments
 (0)