Skip to content

Commit b260518

Browse files
authored
Made amendments as per comments.
1 parent c819d28 commit b260518

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

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

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Imagine we need to write 1 billion. The obvious way is:
1212
let billion = 1000000000;
1313
```
1414

15-
But in real life we usually avoid writing the full number as it's easy to mistype. Also, we are lazy. We will usually write something like `"1bn"` for a billion or `"7.3bn"` for 7 billion 300 million. The same is true for most large numbers.
15+
But in real life we usually avoid writing a long string of zeroes as it's easy to mistype. Also, we are lazy. We will usually write something like `"1bn"` for a billion or `"7.3bn"` for 7 billion 300 million. The same is true for most large numbers.
1616

1717
In JavaScript, we shorten a number by appending the letter `"e"` to the number and specifying the zeroes count:
1818

@@ -125,7 +125,7 @@ There are several built-in functions for rounding:
125125
: Rounds to the nearest integer: `3.1` becomes `3`, `3.6` becomes `4` and `-1.1` becomes `-1`.
126126

127127
`Math.trunc` (not supported by Internet Explorer)
128-
: Removes anything after the decimal without rounding: `3.1` becomes `3`, `-1.1` becomes `-1`.
128+
: Removes anything after the decimal point without rounding: `3.1` becomes `3`, `-1.1` becomes `-1`.
129129

130130
Here's the table to summarize the differences between them:
131131
@@ -145,7 +145,7 @@ There are two ways to do so:
145145

146146
1. Multiply-and-divide.
147147

148-
For example, to round the number to the 2nd digit after the decimal, we can multiply the number by `100`, call the rounding function, and then divide back.
148+
For example, to round the number to the 2nd digit after the decimal, we can multiply the number by `100`, call the rounding function and then divide it back.
149149
```js run
150150
let num = 1.23456;
151151

@@ -159,7 +159,7 @@ There are two ways to do so:
159159
alert( num.toFixed(1) ); // "12.3"
160160
```
161161

162-
This round up or down to the nearest value, similar to `Math.round`:
162+
This rounds up or down to the nearest value, similar to `Math.round`:
163163

164164
```js run
165165
let num = 12.36;
@@ -205,7 +205,7 @@ Ouch! There are more consequences than an incorrect comparison here. Imagine you
205205

206206
But why does this happen?
207207

208-
A number is stored in memory in it's binary form, a sequence of ones and zeroes. But fractions like `0.1`, `0.2` that look simple in the decimal numeric system are actually unending fractions in their binary form.
208+
A number is stored in memory in its binary form, a sequence of ones and zeroes. But fractions like `0.1`, `0.2` that look simple in the decimal numeric system are actually unending fractions in their binary form.
209209

210210
In other words, what is `0.1`? It is one divided by ten `1/10`, one-tenth. In decimal numeral system such numbers are easily representable. Compare it to one-third: `1/3`. It becomes an endless fraction `0.33333(3)`.
211211

@@ -254,7 +254,7 @@ Can we work around the problem? Sure, there're a number of ways:
254254

255255
This works because when we do `0.1*10 = 1` and `0.2 * 10 = 2` then both numbers become integers, and there's no precision loss.
256256

257-
3. If it's we were dealing with a shop, then the most radical solution would be to store all prices in cents and use no fractions at all. But what if we apply a discount of 30%? In practice, totally evading fractions is rarely feasible, so the solutions above help avoid this pitfall.
257+
3. If we were dealing with a shop, then the most radical solution would be to store all prices in cents and use no fractions at all. But what if we apply a discount of 30%? In practice, totally evading fractions is rarely feasible, so the solutions above help avoid this pitfall.
258258

259259
````smart header="The funny thing"
260260
Try running this:
@@ -320,7 +320,7 @@ let num = +prompt("Enter a number", '');
320320
alert( isFinite(num) );
321321
```
322322

323-
Please note that spaces in a string are treated as a `0` in all numeric functions, including `isFinite`.
323+
Please note that an empty or a space-only string is treated as `0` in all numeric functions including `isFinite`.
324324

325325
```smart header="Compare with `Object.is`"
326326

@@ -331,7 +331,7 @@ There is a special built-in method [Object.is](mdn:js/Object/is) that compares v
331331

332332
In all other cases, `Object.is(a, b)` is the same as `a === b`.
333333

334-
This method of comparison is often used in JavaScript. When an internal algorithm needs to compare two values for being exactly the same, it uses `Object.is` (internally called [SameValue](https://tc39.github.io/ecma262/#sec-samevalue)).
334+
This way of comparison is often used in JavaScript specification. When an internal algorithm needs to compare two values for being exactly the same, it uses `Object.is` (internally called [SameValue](https://tc39.github.io/ecma262/#sec-samevalue)).
335335
```
336336

337337

@@ -343,19 +343,19 @@ Numeric conversion using a plus `+` or `Number()` is strict. If a value is not e
343343
alert( +"100px" ); // NaN
344344
```
345345

346-
The sole exception is spaces before and after the line, as they are ignored.
346+
The sole exception is spaces at the beginning or at the end of the string, as they are ignored.
347347

348-
But in real life we often have values in units, like `"100px"` or `"12pt"` in CSS. Also in many countries, the currency symbol goes after the amount, so we have `"19€"`, but would still like to extract a numeric value out of that.
348+
But in real life we often have values in units, like `"100px"` or `"12pt"` in CSS. Also in many countries the currency symbol goes after the amount, so we have `"19€"` and would like to extract a numeric value out of that.
349349

350350
That's what `parseInt` and `parseFloat` are for.
351351

352-
They "read" numbers within a string and unless there's an error (for example, if the first character of a string is not a number), the first valid number is returned. The function `parseInt` returns an integer, whilst `parseFloat` will return a floating-point number:
352+
They "read" a number from a string until they can. In case of an error, the gathered number is returned. The function `parseInt` returns an integer, whilst `parseFloat` will return a floating-point number:
353353

354354
```js run
355355
alert( parseInt('100px') ); // 100
356356
alert( parseFloat('12.5em') ); // 12.5
357357

358-
alert( parseInt('12.3') ); // 12, only the integer is returned
358+
alert( parseInt('12.3') ); // 12, only the integer part is returned
359359
alert( parseFloat('12.3.4') ); // 12.3, the second point stops the reading
360360
```
361361

@@ -423,7 +423,7 @@ For different numeral systems:
423423

424424
For converting values like `12pt` and `100px` to a number:
425425

426-
- Use `parseInt/parseFloat` for the "soft" conversion, which reads a number from a string until broken by something that is not a number.
426+
- Use `parseInt/parseFloat` for the "soft" conversion, which reads a number from a string and then returns the value they could read before the error.
427427

428428
For fractions:
429429

0 commit comments

Comments
 (0)