1 if(!dojo._hasResource["dojo.currency"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
2 dojo._hasResource["dojo.currency"] = true;
3 dojo.provide("dojo.currency");
5 dojo.require("dojo.number");
6 dojo.require("dojo.i18n");
7 dojo.requireLocalization("dojo.cldr", "currency", null, "zh,en-ca,pt,en-us,de,ja,en,en-au,ROOT,fr,es,ko,zh-tw,it");
8 dojo.require("dojo.cldr.monetary");
12 // summary: localized formatting and parsing routines for currencies
16 dojo.currency._mixInDefaults = function(options){
17 options = options || {};
18 options.type = "currency";
20 // Get locale-depenent currency data, like the symbol
21 var bundle = dojo.i18n.getLocalization("dojo.cldr", "currency", options.locale) || {};
23 // Mixin locale-independent currency data, like # of places
24 var iso = options.currency;
25 var data = dojo.cldr.monetary.getData(iso);
27 dojo.forEach(["displayName","symbol","group","decimal"], function(prop){
28 data[prop] = bundle[iso+"_"+prop];
31 data.fractional = [true, false];
33 // Mixin with provided options
34 return dojo.mixin(data, options);
37 dojo.currency.format = function(/*Number*/value, /*dojo.number.__FormatOptions?*/options){
39 // Format a Number as a currency, using locale-specific settings
42 // Create a string from a Number using a known, localized pattern.
43 // [Formatting patterns](http://www.unicode.org/reports/tr35/#Number_Elements) appropriate to the locale are chosen from the [CLDR](http://unicode.org/cldr)
44 // as well as the appropriate symbols and delimiters.
47 // the number to be formatted.
49 return dojo.number.format(value, dojo.currency._mixInDefaults(options));
52 dojo.currency.regexp = function(/*dojo.number.__RegexpOptions?*/options){
55 // Builds the regular needed to parse a currency value
58 // Returns regular expression with positive and negative match, group and decimal separators
59 // Note: the options.places default, the number of decimal places to accept, is defined by the currency type.
60 return dojo.number.regexp(dojo.currency._mixInDefaults(options)); // String
64 dojo.declare("dojo.currency.__ParseOptions", [dojo.number.__ParseOptions], {
66 // currency, set by default.
68 // override currency symbol. Normally, will be looked up in table of supported currencies,
69 // and ISO currency code will be used if not found. See dojo.i18n.cldr.nls->currency.js
71 // number of decimal places to accept. Default is defined by currency.
72 // fractional: Boolean?|Array?
73 // where places are implied by pattern or explicit 'places' parameter, whether to include the fractional portion.
74 // By default for currencies, it the fractional portion is optional.
82 dojo.currency.parse = function(/*String*/expression, /*dojo.currency.__ParseOptions?*/options){
85 // Convert a properly formatted currency string to a primitive Number,
86 // using locale-specific settings.
89 // Create a Number from a string using a known, localized pattern.
90 // [Formatting patterns](http://www.unicode.org/reports/tr35/#Number_Format_Patterns) are chosen appropriate to the locale.
92 // expression: A string representation of a Number
94 return dojo.number.parse(expression, dojo.currency._mixInDefaults(options));