Learn
← Previous Next →

Hari 26: Intl & Internationalization

50 min Last updated 09 Apr 2026

Intl API — Format Angka, Tanggal, Mata Uang

// Format angka
const fmt = new Intl.NumberFormat("id-ID");
fmt.format(1234567.89); // "1.234.567,89"

// Format mata uang
const rupiah = new Intl.NumberFormat("id-ID", {
    style: "currency", currency: "IDR", maximumFractionDigits: 0
});
rupiah.format(8500000); // "Rp 8.500.000"

// Format tanggal
const tgl = new Intl.DateTimeFormat("id-ID", {
    weekday: "long", year: "numeric", month: "long", day: "numeric"
});
tgl.format(new Date("2024-05-17")); // "Jumat, 17 Mei 2024"

// Relative time
const rel = new Intl.RelativeTimeFormat("id-ID", { numeric: "auto" });
rel.format(-3, "day");  // "3 hari yang lalu"
rel.format(2, "week");  // "dalam 2 minggu"

// Sorting dan perbandingan
["mangga","apel","jeruk","pisang"].sort(
    new Intl.Collator("id").compare
); // ["apel","jeruk","mangga","pisang"]

💡 Notice: Intl API adalah standar web untuk internasionalisasi. Tidak perlu library tambahan untuk format mata uang, tanggal, dsb.

Assignment

Buat fungsi formatHarga(angka, mata_uang) yang format harga dalam IDR dan USD. Test dengan 8500000 (IDR) dan 550 (USD). Juga tampilkan tanggal hari ini dalam format Indonesia.

Expected output:

Rp 8.500.000
$550
JS script.js
Solution
Output