-
Notifications
You must be signed in to change notification settings - Fork 179
Numbers #62
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
tarasyyyk
merged 6 commits into
javascript-tutorial:master
from
alexandrtovmach:translation/js-dataTypes-number
Mar 6, 2020
Merged
Numbers #62
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
2206ccf
feat: Completed half of article translation
alexandrtovmach 92fc77f
Apply suggestions from code review
alexandrtovmach d669861
feat: Completed article translation
alexandrtovmach d94a3e3
feat: Completed tasks translation
alexandrtovmach c8d550d
Merge branch 'translation/js-dataTypes-number' of github.com:alexandr…
alexandrtovmach 49766ed
Apply suggestions from code review
alexandrtovmach File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
|
||
|
||
```js run demo | ||
let a = +prompt("The first number?", ""); | ||
let b = +prompt("The second number?", ""); | ||
let a = +prompt("Перше число?", ""); | ||
let b = +prompt("Друге число?", ""); | ||
|
||
alert( a + b ); | ||
``` | ||
|
||
Note the unary plus `+` before `prompt`. It immediately converts the value to a number. | ||
Зверніть увагу на одиничний плюс `+` перед `prompt`. Це відразу перетворює значення в число. | ||
|
||
Otherwise, `a` and `b` would be string their sum would be their concatenation, that is: `"1" + "2" = "12"`. | ||
В іншому випадку, `a` і` b` будуть рядками, і в результаті вони об'єднаються (конкатинуються), тобто: `"1" + "2" = "12"`. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 9 additions & 10 deletions
19
1-js/05-data-types/02-number/2-why-rounded-down/solution.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,32 @@ | ||
Internally the decimal fraction `6.35` is an endless binary. As always in such cases, it is stored with a precision loss. | ||
Десятковий дріб `6.35` являє собою нескінченний двійковий код. Як завжди в таких випадках, він зберігається з втратою точності. | ||
|
||
Let's see: | ||
Подивимось: | ||
|
||
```js run | ||
alert( 6.35.toFixed(20) ); // 6.34999999999999964473 | ||
``` | ||
|
||
The precision loss can cause both increase and decrease of a number. In this particular case the number becomes a tiny bit less, that's why it rounded down. | ||
Втрата точності може спричинити як збільшення, так і зменшення числа. У цьому конкретному випадку число стає трохи меншим, тому воно округляється вниз. | ||
|
||
And what's for `1.35`? | ||
А що для `1.35`? | ||
|
||
```js run | ||
alert( 1.35.toFixed(20) ); // 1.35000000000000008882 | ||
``` | ||
|
||
Here the precision loss made the number a little bit greater, so it rounded up. | ||
Тут втрата точності зробила число трохи більшим, тому воно округляється вверх. | ||
|
||
**How can we fix the problem with `6.35` if we want it to be rounded the right way?** | ||
**Як ми можемо виправити проблему з числом `6.35`, якщо хочемо, щоб воно було правильно округлене?** | ||
|
||
We should bring it closer to an integer prior to rounding: | ||
Ми повинні наблизити його до цілого числа до округлення: | ||
|
||
```js run | ||
alert( (6.35 * 10).toFixed(20) ); // 63.50000000000000000000 | ||
``` | ||
|
||
Note that `63.5` has no precision loss at all. That's because the decimal part `0.5` is actually `1/2`. Fractions divided by powers of `2` are exactly represented in the binary system, now we can round it: | ||
Зауважте, що `63.5` взагалі не має втрат на точність. Це тому, що десяткова частина `0.5` насправді є `1/2`. Дроби, розділені на `2`, точно представлені у двійковій системі, і ми можемо її округлити: | ||
|
||
|
||
```js run | ||
alert( Math.round(6.35 * 10) / 10); // 6.35 -> 63.5 -> 64(rounded) -> 6.4 | ||
alert( Math.round(6.35 * 10) / 10); // 6.35 -> 63.5 -> 64(округлене) -> 6.4 | ||
``` | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.