$.number.currency

Currency method of number helpers

You may want to just display a number in a certain currency with symbol and comma or point in it. Actually you can provide it manually, but the problem will come when we try to switch to a different currency, this is why we provide a helper for converting a number (integer or float) into a real currency like US Dolar or ID rupiah.

$.number.currency(amount, currencyCode, locale, ...options*)

// Example:
$.number.currency(2485000, 'IDR', 'id-ID')
//=> 'Rp 2.485.000,00'

Also, if you guys don't like using Alga.js, you can create this currency helper manually by yourself, this currency helper is equivalent to:

function currency(amount, ccy, locale, options = {}) {
  return new Intl.NumberFormat(locale, { 
    style: 'currency', 
    currency: ccy,
    ...options
  }).format(amount)
}

currency(150, 'USD', 'en-US', {})
//=> "$150.00"

Last updated