Skip to content
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

1-js/05-data-types/02-number #114

Merged
merged 54 commits into from Jun 13, 2018
Merged

1-js/05-data-types/02-number #114

merged 54 commits into from Jun 13, 2018

Conversation

lwjcjmx123
Copy link
Contributor

@lwjcjmx123 lwjcjmx123 commented Jun 6, 2018

翻译完毕 resolve #58

liuwenjun added 2 commits June 6, 2018 11:33
…wjcjmx123/javascript-tutorial-en into translate/1-js/05-data-types/02-number
@sakila1012
Copy link

校对认领

@lwjcjmx123
Copy link
Contributor Author

lwjcjmx123 commented Jun 6, 2018

@sakila1012 注意下最后一个文件很大需要手动点开校对哦
@leviding 改下状态

@@ -1,30 +1,30 @@
Internally the decimal fraction `6.35` is an endless binary. As always in such cases, it is stored with a precision loss.
在`6.35`内部,小数部分是一个无限的二进制。在这种情况下,它存储的时候有一个精度的缺失。

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

数字与汉字之间需要一个空格。
6.35 内部,小数部分是一个无限的二进制。在这种情况下,它存储的时候存在精度的损失。
空格问题有点多,请仔细阅读译文要求

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

精度缺失我觉得跟原文有点差别,但损失也有点不太恰当,可以讨论下


**How can we fix the problem with `6.35` if we want it to be rounded the right way?**
**如果我们希望以正确的方式四舍五入,我们如何使用6.35为例来解决这个问题?**

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

数字与汉字之间需要一个空格。
如果我们希望以正确的方式四舍五入,我们如何使用 6.35 为例来解决这个问题?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

如果希望以正确的方式四舍五入,那么我们如何以 6.35 为例来解决这个问题?


```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的幂的分数在二进制系统中被精确地表示,现在我们可以围绕它来解决问题:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

数字与汉字之间需要一个空格。
请注意 63.5 完全没有精度损失。这是因为小数部分 0.5 实际上是 1/2。除以 2 的幂的分数在二进制系统中可以精确地表示,现在我们可以围绕它来解决问题:


According to the documentation `Math.round` and `toFixed` both round to the nearest number: `0..4` lead down while `5..9` lead up.
根据文档`Math.round`和`toFixed`,最近的数字四舍五入:`0..4`会被舍去,而`5..9`会前进一位。

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

数字与汉字之间需要一个空格。
根据文档 Math.roundtoFixed,最近的数字四舍五入:0..4 会被舍去,而 5..9 会前进一位。


```js run
alert( 1.35.toFixed(1) ); // 1.4
```

In the similar example below, why is `6.35` rounded to `6.3`, not `6.4`?
在下面的类似例子中,为什么6.35被四舍五入为6.3而不是6.4?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

数字与汉字之间需要一个空格。
在下面的类似例子中,为什么 6.35 被四舍五入为 6.3 而不是 6.4?


```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.
精度缺失可能会导致数字的增加和减少。在这种特殊情况下,数字可能会变少了一点,这就是为什么它减少了。

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

精度缺失可能会导致数字的增加和减小。在这种特殊情况下,数字可能会变小了一点,这就是为什么它减小了。
数字不应该是减少。


```js run
alert( 1.35.toFixed(20) ); // 1.35000000000000008882
```

Here the precision loss made the number a little bit greater, so it rounded up.
在这里,精确度的损失使得这个数字更大一些,所以这个数字变了。

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the precision loss 翻译应该与上文保持一致。
所以这个数字被五入了。


---

# An occasional infinite loop
#一个偶然出现的无限循环

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

一个偶发的无限循环

1. If we multiply a random number from 0..1 by `max-min`, then it the interval of possible values increases `0..1` to `0..max-min`.
2. Now if we add `min`, the possible interval becomes from `min` to `max`.
1. 如果我们将0..1的随机数乘以`max-min`,则可能值的间隔从0..1增加到0..`max-min`
2. 现在,如果我们添加`最小值`,则可能的间隔将从最小值变为`最大值`。

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

现在,如果我们添加最小值,则可能的间隔将从最小值变为最大值



Examples of its work:
功能示例:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

与上文保持一致

@sakila1012
Copy link

@leviding 校对完毕

Copy link

@sakila1012 sakila1012 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不要把原文删了

@@ -79,9 +79,9 @@ alert( a == b ); // true, the same number 255 at both sides

## toString(base)

方法`num.toStringbase`返回带有给定`base`的数字系统中`num`的字符串表示。
方法`num.toString(base)`返回带有给定`base`的进制中`num`的字符串表示。

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

方法 num.toString(base) 返回带有给定 base 的进制中 num 的字符串表示。

```warn header =“调用方法的两个点”
请注意`123456..toString36)`中的两个点不是拼写错误。如果我们想直接在一个数字上调用一个方法,比如上面例子中的`toString`,那么我们需要在它后面放置两个点`..`。
```需要注意的标题 =“调用方法的两个点”
请注意`123456..toString(36)`中的两个点不是拼写错误。如果我们想直接在一个数字上调用一个方法,比如上面例子中的`toString`,那么我们需要在它后面放置两个点`..`。

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

请注意 123456..toString(36) 中的两个点不是拼写错误。如果我们想直接在一个数字上调用一个方法,比如上面例子中的 toString,那么我们需要在它后面放置两个点..


如果我们放置一个点:`123456.toString(36)`,那么会出现错误,因为JavaScript语法暗示了第一个点之后的小数部分。如果我们再放一个点,那么JavaScript知道小数部分是空的,现在进入方法。
如果我们放置一个点:`123456.toString(36)`,那么会出现错误,因为JavaScript语法暗示了第一个点之后的小数部分。如果我们再放一个点,那么JavaScript知道小数部分是空的,现在进入方法。

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

如果我们放置一个点:123456.toString(36),那么会出现错误,因为 JavaScript 语法暗示了第一个点之后的小数部分。如果我们再放一个点,那么 JavaScript 知道小数部分是空的,现在进入方法。


也可以写`123456.toString(36)`。
也可以写`(123456).toString(36)`。

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

也可以写 (123456).toString(36)

@@ -137,7 +137,7 @@ alert( num.toString(2) ); // 11111111
|`-1.6`| `-2` | `-1` | `-2` | `-1` |


这些函数涵盖处理数字小数部分的所有可能方法。但是如果我们想在十进制后将数字四舍五入到“n”位呢?
这些函数涵盖处理数字小数部分的所有可能方法。但是如果我们想在十进制后将数字四舍五入到`n`位呢?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这些函数涵盖处理数字小数部分的所有可能方法。但是如果我们想在十进制后将数字四舍五入到 n 位呢?

@@ -213,7 +213,7 @@ alert( 0.1 + 0.2 ); // 0.30000000000000004

使用二进制系统只能存储*0.1* 或 *0.2*,就像没有办法将三分之一存储为小数部分一样。

数字格式IEEE-754通过四舍五入到最接近的可能数字来解决此问题。这些舍入规则通常不允许我们看到极小的精确度损失,因此数字显示为0.3。但要小心,损失依然存在。
数字格式IEEE-754通过四舍五入到最接近的可能数字来解决此问题。这些舍入规则通常不允许我们看到`极小的精确度损失`,因此数字显示为`0.3`。但要小心,损失依然存在。

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

数字格式 IEEE-754 通过四舍五入到最接近的可能数字来解决此问题。这些舍入规则通常不允许我们看到极小的精度损失,因此数字显示为 0.3。但要小心,损失依然存在。

@@ -266,15 +266,15 @@ alert( 9999999999999999 ); // shows 10000000000000000

出现了同样的问题:精度的损失。该号码有64位,其中52位可用于存储数字,但这还不够。所以最不重要的数字就消失了。

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

出现了同样的问题:精度的损失。该号码有 64 位,其中 52 位可用于存储数字,但这还不够。所以最不重要的数字就消失了。

@@ -266,15 +266,15 @@ alert( 9999999999999999 ); // shows 10000000000000000

出现了同样的问题:精度的损失。该号码有64位,其中52位可用于存储数字,但这还不够。所以最不重要的数字就消失了。

JavaScript在这种事件中不会触发错误。它尽最大努力使数字符合所需的格式,但不幸的是,这种格式不够大
JavaScript在这种事件中不会触发错误。它尽最大努力使数字符合所需的格式,但不幸的是,这种格式不够大到满足需求

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JavaScript 在这种事件中不会触发错误。它尽最大努力使数字符合所需的格式,但不幸的是,这种格式不够大到满足需求。

@@ -345,7 +345,7 @@ alert( +"100px" ); // NaN

唯一的例外是字符串开头或结尾的空格,因为它们会被忽略。

但在现实生活中,我们经常以单位表示值,比如CSS中的`"100px"`或`"100px"`。在许多国家,货币符号也超过了金额,所以我们有`"19€"`,并希望从中提取一个数值。
但在现实生活中,我们经常以单位表示值,比如CSS中的`"100px"`或`"12pt"`。在许多国家,货币符号也超过了金额,所以我们有`"19€"`,并希望从中提取一个数值。

这就是`parseInt`和`parseFloat`的作用。

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这就是 parseIntparseFloat 的作用。

@@ -345,7 +345,7 @@ alert( +"100px" ); // NaN

唯一的例外是字符串开头或结尾的空格,因为它们会被忽略。

但在现实生活中,我们经常以单位表示值,比如CSS中的`"100px"`或`"100px"`。在许多国家,货币符号也超过了金额,所以我们有`"19€"`,并希望从中提取一个数值。
但在现实生活中,我们经常以单位表示值,比如CSS中的`"100px"`或`"12pt"`。在许多国家,货币符号也超过了金额,所以我们有`"19€"`,并希望从中提取一个数值。

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

但在现实生活中,我们经常以单位表示值,比如 CSS 中的 "100px" "12pt"。在许多国家,货币符号也超过了金额,所以我们有 "19€",并希望从中提取一个数值。

@leviding
Copy link
Member

leviding commented Jun 8, 2018

@lwjcjmx123 还是存在格式问题,我给改了一些,请看记录。对照记录和译者教程,明确什么样的地方应该用什么格式。逗号句号等前后是不加空格的,代码的半角符号是不要改成全角的,因为影响编译运行等等

请认真对照教程,修改最后一个文件。

@leviding leviding added help wanted Extra attention is needed enhancement New feature or request and removed help wanted Extra attention is needed labels Jun 8, 2018
@lwjcjmx123
Copy link
Contributor Author

@leviding 之前偷懒写了个正则全局给那个引号前后加了空格/doge 。。好吧,我还是小看这文章翻译的格式要求了。

@leviding leviding added WIP Work in process and removed enhancement New feature or request labels Jun 11, 2018
@lwjcjmx123
Copy link
Contributor Author

lwjcjmx123 commented Jun 12, 2018

@leviding ok,又改了几个地方。可能我对这个有些中英文符号不太敏感,发现不出来。空格问题又检查了一遍

@leviding
Copy link
Member

@lwjcjmx123 问题还是很多,这次我就直接给修改了,但是之后是不会再这样修改的了,这些都是需要译者去看教程完成的,完成不了的 PR 将被 colse。请认真看下我的几个 commit,译文问题到底出现在哪,之后的翻译需要杜绝此类问题。

@leviding leviding merged commit a09b860 into javascript-tutorial:zh-hans Jun 13, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants