File tree Expand file tree Collapse file tree 2 files changed +8
-3
lines changed Expand file tree Collapse file tree 2 files changed +8
-3
lines changed Original file line number Diff line number Diff line change 1111 *
1212 * @param {number } amount Input to filter.
1313 * @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
1515 * @returns {string } Formatted number.
1616 *
1717 *
@@ -61,8 +61,7 @@ function currencyFilter($locale) {
6161 }
6262
6363 if ( isUndefined ( fractionSize ) ) {
64- // TODO: read the default value from the locale file
65- fractionSize = 2 ;
64+ fractionSize = formats . PATTERNS [ 1 ] . maxFrac ;
6665 }
6766
6867 // if null or undefined pass it through
Original file line number Diff line number Diff line change @@ -120,6 +120,12 @@ describe('filters', function() {
120120 expect ( currency ( 0.008 ) ) . toBe ( '$0.01' ) ;
121121 expect ( currency ( 0.003 ) ) . toBe ( '$0.00' ) ;
122122 } ) ;
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+ } ) ) ;
123129 } ) ;
124130
125131
You can’t perform that action at this time.
0 commit comments