Math
DuckDB
ROUND
Membulatkan angka ke jumlah desimal tertentu. Default ke 0 desimal (bilangan bulat).
Tipe hasil:
Sama dengan tipe inputDiperbarui: 6 Jan 2026Syntax
SQL
ROUND(number [, decimal_places])Parameter
numbernumericwajib
Angka yang akan dibulatkan
decimal_placesINTEGERopsional
Jumlah desimal (default: 0). Negatif untuk pembulatan ke puluhan/ratusan
Default: 0
Contoh Penggunaan
Pembulatan Dasar
SQL
1 SELECT 2 ROUND(3.14159) as default_round, 3 ROUND(3.14159, 2) as two_decimal, 4 ROUND(3.14159, 4) as four_decimal;
Pembulatan dengan berbagai presisi.
Hasil
| default_round | two_decimal | four_decimal |
|---|---|---|
| 3 | 3.14 | 3.1416 |
Pembulatan ke Puluhan/Ratusan
SQL
1 SELECT 2 ROUND(1234, -1) as to_tens, 3 ROUND(1234, -2) as to_hundreds, 4 ROUND(1234, -3) as to_thousands;
Menggunakan decimal_places negatif.
Hasil
| to_tens | to_hundreds | to_thousands |
|---|---|---|
| 1230 | 1200 | 1000 |
Format Persentase
SQL
1 SELECT 2 category, 3 COUNT(*) as count, 4 ROUND(COUNT(*) * 100.0 / SUM(COUNT(*)) OVER (), 2) as percentage 5 FROM orders 6 GROUP BY category;
Menghitung persentase dengan 2 desimal.
Hasil
| category | count | percentage |
|---|---|---|
| Electronics | 450 | 45.00 |
| Clothing | 350 | 35.00 |
| Books | 200 | 20.00 |
Harga ke Ratusan Terdekat
SQL
1 SELECT 2 product_name, 3 price, 4 ROUND(price, -2) as rounded_price 5 FROM products;
Membulatkan harga ke ratusan terdekat.