Skip to content

Commit cb20644

Browse files
committed
1.05.02 (number)
1 parent 69bbd36 commit cb20644

File tree

1 file changed

+28
-28
lines changed

1 file changed

+28
-28
lines changed

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

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -16,89 +16,89 @@ Bayangkan kita harus menulis 1 milyar. Cara jelasnya begini:
1616
let billion = 1000000000;
1717
```
1818

19-
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.
19+
Tapi di kehidupan nyata, kita biasanya menghindari menulis string nol yang panjang karena rentan terjadi kesalahan. Selain itu, kita malas. Kita biasanya akan menulis sesuatu seperti `"1bn"` untuk milyar atau `"7.3bn"` untuk 7 milyar 300 juta. Sama halnya dengan angka besar lainnya.
2020

21-
In JavaScript, we shorten a number by appending the letter `"e"` to the number and specifying the zeroes count:
21+
Di JavaScript, kita perpendek angka dengan menambah huruf `"e"` ke angka dan menspesifikasi jumlah nol:
2222

2323
```js run
24-
let billion = 1e9; // 1 billion, literally: 1 and 9 zeroes
24+
let billion = 1e9; // 1 milyar, literalnya: 1 dan 9 nol
2525

26-
alert( 7.3e9 ); // 7.3 billions (7,300,000,000)
26+
alert( 7.3e9 ); // 7.3 milyar (7,300,000,000)
2727
```
2828

29-
In other words, `"e"` multiplies the number by `1` with the given zeroes count.
29+
Dengan kata lain, `"e"` kalikan angkanya dengan `1` dengan jumlah nol yang diberikan.
3030

3131
```js
3232
1e3 = 1 * 1000
3333
1.23e6 = 1.23 * 1000000
3434
```
3535

36-
Now let's write something very small. Say, 1 microsecond (one millionth of a second):
36+
Sekarang ayo tulis sesuatu lebih kecil. Katakan, 1 microsecond (sepersejuta second):
3737

3838
```js
3939
let ms = 0.000001;
4040
```
4141

42-
Just like before, using `"e"` can help. If we'd like to avoid writing the zeroes explicitly, we could say the same as:
42+
Sama seperti sebelumnya, memakai `"e"` bisa membantu. Jika kita ingin menghindari menulis nol eksplisit, kita bisa katakan hal yang sama:
4343

4444
```js
45-
let ms = 1e-6; // six zeroes to the left from 1
45+
let ms = 1e-6; // enam nol di sebelah kiri dari 1
4646
```
4747

48-
If we count the zeroes in `0.000001`, there are 6 of them. So naturally it's `1e-6`.
48+
Jika kita hitung nol di `0.000001`, ada 6 dari mereka. Jadi alaminya `1e-6`.
4949

50-
In other words, a negative number after `"e"` means a division by 1 with the given number of zeroes:
50+
Dengan kata lain, angka negatif setelah `"e"` artinya pembagian 1 dengan jumlah nol yang diberikan:
5151

5252
```js
53-
// -3 divides by 1 with 3 zeroes
53+
// -3 membagi 1 dengan 3 nol
5454
1e-3 = 1 / 1000 (=0.001)
5555

56-
// -6 divides by 1 with 6 zeroes
56+
// -6 membagi 1 dengan 6 nol
5757
1.23e-6 = 1.23 / 1000000 (=0.00000123)
5858
```
5959

60-
### Hex, binary and octal numbers
60+
### Hex, angka binary dan octal
6161

62-
[Hexadecimal](https://en.wikipedia.org/wiki/Hexadecimal) numbers are widely used in JavaScript to represent colors, encode characters, and for many other things. So naturally, there exists a shorter way to write them: `0x` and then the number.
62+
Angka [Hexadecimal](https://en.wikipedia.org/wiki/Hexadecimal) secara luas dipakai di JavaScript untuk mewakili warna, encode karakter, dan banyak hal lain. Alaminya, ada cara lebih singkat menulis mereka: `0x` kemudian angkanya.
6363

64-
For instance:
64+
Misalnya:
6565

6666
```js run
6767
alert( 0xff ); // 255
68-
alert( 0xFF ); // 255 (the same, case doesn't matter)
68+
alert( 0xFF ); // 255 (sama, case diabaikan)
6969
```
7070

71-
Binary and octal numeral systems are rarely used, but also supported using the `0b` and `0o` prefixes:
71+
Sistem numeral binary dan octal jarang dipakai, tapi juga didukung menggunakan prefix `0b` dan `0o`:
7272

7373

7474
```js run
75-
let a = 0b11111111; // binary form of 255
76-
let b = 0o377; // octal form of 255
75+
let a = 0b11111111; // bentuk binary dari 255
76+
let b = 0o377; // bentuk octal dari 255
7777

78-
alert( a == b ); // true, the same number 255 at both sides
78+
alert( a == b ); // true, angka sama 255 dari kedua sisi
7979
```
8080

81-
There are only 3 numeral systems with such support. For other numeral systems, we should use the function `parseInt` (which we will see later in this chapter).
81+
Cuma ada 3 sistem numeral dengan dukungan begitu. Untuk sistem numeral lain, kita sebaiknya memakai fungsi `parseInt` (yang akan kita lihat nanti di bab ini).
8282

8383
## toString(base)
8484

85-
The method `num.toString(base)` returns a string representation of `num` in the numeral system with the given `base`.
85+
Metode `num.toString(base)` mengembalikan representasi string dari `num` di sistem numeral dengan `base` yang diberikan.
8686

87-
For example:
87+
Misalnya:
8888
```js run
8989
let num = 255;
9090

9191
alert( num.toString(16) ); // ff
9292
alert( num.toString(2) ); // 11111111
9393
```
9494

95-
The `base` can vary from `2` to `36`. By default it's `10`.
95+
`base` bisa bervariasi dari `2` hingga `36`. Defaultnya `10`.
9696

97-
Common use cases for this are:
97+
Penggunaan umumnya ialah:
9898

99-
- **base=16** is used for hex colors, character encodings etc, digits can be `0..9` or `A..F`.
100-
- **base=2** is mostly for debugging bitwise operations, digits can be `0` or `1`.
101-
- **base=36** is the maximum, digits can be `0..9` or `A..Z`. The whole latin alphabet is used to represent a number. A funny, but useful case for `36` is when we need to turn a long numeric identifier into something shorter, for example to make a short url. Can simply represent it in the numeral system with base `36`:
99+
- **base=16** dipakai untuk warna hex, character encoding dll, digit bisa `0..9` atau `A..F`.
100+
- **base=2** paling banyak untuk mendebug operasi bitwise, digit bisa `0` atau `1`.
101+
- **base=36** ini maximum, digit bisa `0..9` atau `A..Z`. Seluruh alfabet latin dipakai untuk merepresentasi angka. Hal lucu, tapi berguna untuk `36` ialah saat kita harus mengubah identifier numerik panjang ke dalam sesuatu yang lebih pendek, misalnya untuk membuat url pendek. Bisa direpresentasikan dalam sistem `36`:
102102

103103
```js run
104104
alert( 123456..toString(36) ); // 2n9c

0 commit comments

Comments
 (0)