Skip to content

Commit f9465fa

Browse files
committed
Update
- Fixed : abbreviating currencies
1 parent 58dca3c commit f9465fa

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

resources/ts/filters/currency.ts

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ declare const window;
88
const precision = ( new Array( parseInt( ns.currency.ns_currency_precision ) ) ).fill('').map( _ => 0 ).join('');
99

1010
const nsCurrency = Vue.filter( 'currency', ( value, format = 'full', locale = 'en' ) => {
11+
console.log( format );
1112
let numeralFormat, currencySymbol;
1213

1314
switch( ns.currency.ns_currency_prefered ) {
@@ -19,16 +20,23 @@ const nsCurrency = Vue.filter( 'currency', ( value, format = 'full', lo
1920
break;
2021
}
2122

22-
const config = {
23-
decimal: ns.currency.ns_currency_decimal_separator,
24-
separator: ns.currency.ns_currency_thousand_separator,
25-
precision : parseInt( ns.currency.ns_currency_precision ),
26-
symbol: ''
27-
};
23+
let newValue;
24+
25+
if ( format === 'full' ) {
26+
const config = {
27+
decimal: ns.currency.ns_currency_decimal_separator,
28+
separator: ns.currency.ns_currency_thousand_separator,
29+
precision : parseInt( ns.currency.ns_currency_precision ),
30+
symbol: ''
31+
};
32+
33+
newValue = currency( value, config ).format();
34+
} else {
35+
newValue = NumeralJS( value ).format( '0.0a' );
36+
}
2837

29-
const currencyValue = currency( value, config );
38+
return `${ns.currency.ns_currency_position === 'before' ? currencySymbol : '' }${ newValue }${ns.currency.ns_currency_position === 'after' ? currencySymbol : '' }`;
3039

31-
return `${ns.currency.ns_currency_position === 'before' ? currencySymbol : '' }${ currencyValue.format() }${ns.currency.ns_currency_position === 'after' ? currencySymbol : '' }`;
3240
});
3341

3442
const nsRawCurrency = ( value ) => {

0 commit comments

Comments
 (0)