Function currency

  • Formats a numeric or string value as currency based on the specified format and currency.

    Parameters

    • value: string | number

      The numeric or string value to be formatted as currency.

    • format: "en-US" | "id-ID"

      The format to be used for the number representation (e.g., 'en-US' for English, 'id-ID' for Indonesian).

    • currency: "IDR" | "USD"

      The currency code to be used for formatting (e.g., 'IDR' for Indonesian Rupiah, 'USD' for US Dollar).

    Returns string

    • The formatted currency string.
    // Format a value as USD currency
    const result = currencyFormatter(1234.56, 'en-US', 'USD');
    console.log(result); // Output: $1,234.56
    // Format a value as IDR currency
    const result = currencyFormatter('7890.12', 'id-ID', 'IDR');
    console.log(result); // Output: Rp 7.890,12