Alga.js
  • Introduction
  • Installation
  • Array
    • $.array.insert
    • $.array.update
    • $.array.destroy
    • $.array.select
    • $.array.hidden
    • $.array.search
    • $.array.filter
    • $.array.paginate
    • $.array.sort
    • $.array.setOperations
    • $.array.sum
    • $.array.calculate
  • Object
    • $.object.remove
  • String & Char
    • $string.split
    • $.char.random
  • Number (Int & Float)
    • $.number.calc
    • $.number.currency
  • Date
    • $.date.now
    • $.date.format
    • $.date.parse
    • $.date.days
    • $.date.weeks
    • $.date.months
    • $date.calendar
Powered by GitBook
On this page

Was this helpful?

  1. Number (Int & Float)

$.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"
Previous$.number.calcNext$.date.now

Last updated 3 years ago

Was this helpful?