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
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.
10
-
11
-
And what's for `1.35`?
7
+
این از دست دادن دقت میتواند در هم مقدار عدد را افزایش یا کاهش دهد. در این حالت خاص، عدد اندکی کوچک میشود، به همین علت به پایین رند میشود.
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:
28
-
24
+
توجه داشته باشید که `63.5` هیچ از دست دادن دقتی ندارد. به خاطر قسمت اعشاری آن `0.5` که در اصل `1/2` است. کسرهای تقسیم شده بر دو به درستی در سیستم دودویی نمایش داده میشوند، حالا میتوانیم آن را رند کنیم:
Copy file name to clipboardExpand all lines: 1-js/05-data-types/02-number/3-repeat-until-number/solution.md
+3-4Lines changed: 3 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -15,9 +15,8 @@ function readNumber() {
15
15
alert(`Read: ${readNumber()}`);
16
16
```
17
17
18
-
The solution is a little bit more intricate that it could be because we need to handle `null`/empty lines.
18
+
جواب اندکی پیچیدهست که به خاطر این است که باید `null`/خالی را هم در نظر بگیریم.
19
19
20
-
So we actually accept the input until it is a "regular number". Both `null` (cancel) and empty line also fit that condition, because in numeric form they are `0`.
21
-
22
-
After we stopped, we need to treat `null` and empty line specially (return `null`), because converting them to a number would return `0`.
20
+
پس ما تا وقتی ورودی را میپذیریم که عدد عادی باشد. هردوی `null` (cancel) و خط خالی هم در این شرایط میگنجد، چونکه در فرم عددی صفر هستند.
23
21
22
+
بعد از اینکه برنامه متوقف شد بایستی `null` و مخصوصا خطهای خالی (خروجی `null`) را در نظر بگیریم، چون تبدیل آنها به عدد صفر برمیگرداند.
0 commit comments