简体   繁体   中英

How to remove currency symbol, when formatting currency using Globalizejs library?

I am using Globalizejs to format Currency based on Logged-In user details in my application.

I don't want currency Symbol to be displayed when formatting is done using below code snippet:

Globalize.locale( "en" );
currencyFormatter = Globalize.currencyFormatter( "USD", {
  maximumFractionDigits: 0,
});

currencyFormatter(parseInt(totalCost.amount));

which returns

$1,212,122,112 for amount: 1212122112

Is there any option similar to maximumFractionDigits to avoid the currency symbol ?

Short answer: Globalize.numberFormatter

Longer answer: Two benefits of using currency formatter is: (a) have the currency symbol properly formatted, and (b) have the appropriate number of fraction digits properly formatted; note that several currencies such as USD, EUR, have 2 fraction digits by default, but others like JPY have 0, there are different cases too.

The appropriate solution to customize the markup and style of a formatted output is to use parts Globalize.currencyToPartsFormatter : At the time we speak, this feature isn't implemented yet https://github.com/globalizejs/globalize/issues/679 .

As a workaround, which should work fine for your specific use case (no currency symbol + integers only amount), using Globalize.numberFormatter should suffice.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM