CurrencyFmatter. js is a simple and practical pure js formatting currency plug-in. The plug-in contains 155 currencies in different countries and 715 localization settings for different languages. It can also handle some unused currencies and has very powerful functions.
HTML
First introduce the currencyFormatter. js file in the page.
<Script src = 'currencyformatter. Js'> </script>
HTML structure:
<Div class = 'Money'> 1234536.32 </div>
<Div class = 'Money'> 8798458.11 </div>
Javascript
OSREC. CurrencyFormatter. formatAll (
{
Selector: '. Money ',
Currency: 'cny'
});
As you can see, the selector corresponds to currency, which corresponds to CNY.
The OSREC. CurrencyFormatter. format (number, parameters) method can easily format a currency value. You only need to set the desired format in the configuration parameters. The parameter format is as follows:
Var parameters =
{
Currency: 'eur', // If currency is not supplied, defaults to USD
Symbol :'? #39;, // Overrides the currency's default symbol
Locale: 'Fr ', // Overrides the currency's default locale (see supported locales)
Decimal: ',', // Overrides the locale's decimal character
Group: '.', // Overrides the locale's group character (thousand separator)
Pattern: '#, #0.00! '// Overrides the locale's default display pattern
// The pattern follows standard unicode currency pattern notation.
// Comma = group separator, dot = decimal separator, exclamation = currency symbol
}
Generally, you do not need to specify all parameters. The plug-in displays the settings of each currency and language in an appropriate format.
OSREC. CurrencyFormatter. format (2534234, {currency: 'inr '}); // Returns? 25,34, 234.00
OSREC. CurrencyFormatter. format (2534234, {currency: 'eur'}); // Returns 2.534.234, 00? /Code>
OSREC. CurrencyFormatter. format (2534234, {currency: 'eur', locale: 'Fr '}); // Returns 2 534?
Using the OSREC. CurrencyFormatter. formatAll (parameters) method, you can convert all the elements that contain values into nice-looking currency formats.