This repository was archived by the owner on Apr 12, 2024. It is now read-only.
File tree 2 files changed +8
-3
lines changed
2 files changed +8
-3
lines changed Original file line number Diff line number Diff line change 11
11
*
12
12
* @param {number } amount Input to filter.
13
13
* @param {string= } symbol Currency symbol or identifier to be displayed.
14
- * @param {number= } fractionSize Number of decimal places to round the amount to.
14
+ * @param {number= } fractionSize Number of decimal places to round the amount to, defaults to default max fraction size for current locale
15
15
* @returns {string } Formatted number.
16
16
*
17
17
*
@@ -61,8 +61,7 @@ function currencyFilter($locale) {
61
61
}
62
62
63
63
if ( isUndefined ( fractionSize ) ) {
64
- // TODO: read the default value from the locale file
65
- fractionSize = 2 ;
64
+ fractionSize = formats . PATTERNS [ 1 ] . maxFrac ;
66
65
}
67
66
68
67
// if null or undefined pass it through
Original file line number Diff line number Diff line change @@ -120,6 +120,12 @@ describe('filters', function() {
120
120
expect ( currency ( 0.008 ) ) . toBe ( '$0.01' ) ;
121
121
expect ( currency ( 0.003 ) ) . toBe ( '$0.00' ) ;
122
122
} ) ;
123
+
124
+ it ( 'should set the default fraction size to the max fraction size of the locale value' , inject ( function ( $locale ) {
125
+ $locale . NUMBER_FORMATS . PATTERNS [ 1 ] . maxFrac = 1 ;
126
+
127
+ expect ( currency ( 1.07 ) ) . toBe ( '$1.1' ) ;
128
+ } ) ) ;
123
129
} ) ;
124
130
125
131
You can’t perform that action at this time.
0 commit comments