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
Copy file name to clipboardExpand all lines: 1-js/05-data-types/02-number/article.md
+22-22Lines changed: 22 additions & 22 deletions
Original file line number
Diff line number
Diff line change
@@ -104,33 +104,33 @@ Penggunaan umumnya ialah:
104
104
alert( 123456..toString(36) ); // 2n9c
105
105
```
106
106
107
-
```warn header="Two dots to call a method"
108
-
Please note that two dots in`123456..toString(36)`is not a typo. If we want to call a method directly on a number, like`toString`in the example above, then we need to place two dots `..`after it.
107
+
```warn header="Dua dot untuk memanggil metode"
108
+
Tolong ingat bahwa dua dot di`123456..toString(36)`bukan typo. Jika kita mau memanggil langsung metode pada angka, seperti`toString`di contoh di atas, maka kita harus menaruh dua dot `..`setelahnya.
109
109
110
-
If we placed a single dot: `123456.toString(36)`, then there would be an error, because JavaScript syntax implies the decimal part after the first dot. And if we place one more dot, then JavaScript knows that the decimal part is empty and now goes the method.
110
+
Jika kita menaruh dot tunggal: `123456.toString(36)`, maka akan ada galat, karena syntax JavaScript berimplikasi bahwa bagian desimal setelah dot pertama. Dan jika kita menaruh satu dot lagi, maka JavaScript tahu bahwa bagian desimal kosong dan sekarang pergi ke metode.
111
111
112
-
Also could write`(123456).toString(36)`.
112
+
Juga bisa menulis`(123456).toString(36)`.
113
113
```
114
114
115
-
## Rounding
115
+
## Pembulatan
116
116
117
-
One of the most used operations when working with numbers is rounding.
117
+
Satu dari operasi paling banyak dipakai saat bekerja dengan angka ialah pembulatan.
@@ -140,43 +140,43 @@ Here's the table to summarize the differences between them:
140
140
|`-1.6`|`-2`|`-1`|`-2`|`-1`|
141
141
142
142
143
-
These functions cover all of the possible ways to deal with the decimal part of a number. But what if we'd like to round the number to `n-th` digit after the decimal?
143
+
Fungsi ini membahas semua cara yang mungkin untuk berhadapan dengan bagian desimal dari angka. Tapi bagaimana jika kita mau membulatkan angka ke digit `ke-n` setelah desimal?
144
144
145
-
For instance, we have`1.2345`and want to round it to 2 digits, getting only`1.23`.
145
+
Misalnya, kita punya`1.2345`dan mau membulatkan ke 2 digit, memperoleh`1.23`.
146
146
147
-
There are two ways to do so:
147
+
Ada dua cara melakukannya:
148
148
149
-
1.Multiply-and-divide.
149
+
1.Kali-dan-bagi.
150
150
151
-
For example, to round the number to the 2nddigit after the decimal, we can multiply the number by `100`, call the rounding function and then divide it back.
151
+
Misalnya, untuk membulatkan angka ke digit kedua setelah desimal, kita bisa mengalikan angkanya dengan `100`, panggil fungsi pembulatan lalu membagi itu kembali.
2. The method [toFixed(n)](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toFixed) rounds the number to `n` digits after the point and returns a string representation of the result.
158
+
2.Metode [toFixed(n)](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toFixed) Membulatkan ke digit `n` setelah poin itu dan mengembalikan representasi string dari hasilnya.
159
159
160
160
```js run
161
161
let num = 12.34;
162
162
alert( num.toFixed(1) ); // "12.3"
163
163
```
164
164
165
-
This rounds up or down to the nearest value, similar to `Math.round`:
165
+
Ini membulatkan ke atas atau ke bawah ke nilai terdekat, serupa dengan`Math.round`:
166
166
167
167
```js run
168
168
let num = 12.36;
169
169
alert( num.toFixed(1) ); // "12.4"
170
170
```
171
171
172
-
Please note that result of `toFixed` is a string. If the decimal part is shorter than required, zeroes are appended to the end:
172
+
Silakan catat hasil dari `toFixed`ialah string. Jika bagian desimal lebih pendek dari yang dibutuhkan, nol ditambahkan di akhir:
173
173
174
174
```js run
175
175
let num = 12.34;
176
-
alert( num.toFixed(5) ); // "12.34000", added zeroes to make exactly 5 digits
We can convert it to a number using the unary plus or a `Number()` call: `+num.toFixed(5)`.
179
+
Kita bisa mengkonversi itu ke angka menggunakan unary plus atau panggilan`Number()`:`+num.toFixed(5)`.
180
180
181
181
## Imprecise calculations
182
182
@@ -408,7 +408,7 @@ A few examples:
408
408
409
409
There are more functions and constants in `Math` object, including trigonometry, which you can find in the [docs for the Math](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Math) object.
0 commit comments