Format currency with pure js: Usage of currencyFmatter. js

Source: Internet
Author: User
Tags locale

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.