Merge pull request #420 from TheZoker/adjust-money-format

Adjust money format to respect swap_currency_symbol
This commit is contained in:
Mohit Panjwani
2021-03-22 12:12:13 +05:30
committed by GitHub
2 changed files with 18 additions and 27 deletions

View File

@ -37,7 +37,8 @@ class CurrenciesTableSeeder extends Seeder
'symbol' => '€', 'symbol' => '€',
'precision' => '2', 'precision' => '2',
'thousand_separator' => '.', 'thousand_separator' => '.',
'decimal_separator' => ',' 'decimal_separator' => ',',
'swap_currency_symbol' => true
], ],
[ [
'name' => 'South African Rand', 'name' => 'South African Rand',

View File

@ -23,7 +23,7 @@ export default {
amount = amount / 100 amount = amount / 100
let { precision, decimal_separator, thousand_separator, symbol } = currency let { precision, decimal_separator, thousand_separator, symbol, swap_currency_symbol } = currency
try { try {
precision = Math.abs(precision) precision = Math.abs(precision)
@ -37,19 +37,14 @@ export default {
let j = i.length > 3 ? i.length % 3 : 0 let j = i.length > 3 ? i.length % 3 : 0
let moneySymbol = `<span style="font-family: sans-serif">${symbol}</span>` let moneySymbol = `<span style="font-family: sans-serif">${symbol}</span>`
let thousandText = (j ? i.substr(0, j) + thousand_separator : '')
let amountText = i.substr(j).replace(/(\d{3})(?=\d)/g, '$1' + thousand_separator)
let precisionText = (precision ? decimal_separator + Math.abs(amount - i).toFixed(precision).slice(2) : '');
let combinedAmountText = negativeSign + thousandText + amountText + precisionText
return ( return (swap_currency_symbol
moneySymbol + ? combinedAmountText + ' ' + moneySymbol
' ' + : moneySymbol + ' ' + combinedAmountText
negativeSign +
(j ? i.substr(0, j) + thousand_separator : '') +
i.substr(j).replace(/(\d{3})(?=\d)/g, '$1' + thousand_separator) +
(precision
? decimal_separator +
Math.abs(amount - i)
.toFixed(precision)
.slice(2)
: '')
) )
} catch (e) { } catch (e) {
console.log(e) console.log(e)
@ -68,7 +63,7 @@ export default {
amount = amount / 100 amount = amount / 100
let { precision, decimal_separator, thousand_separator, symbol } = currency let { precision, decimal_separator, thousand_separator, symbol, swap_currency_symbol } = currency
try { try {
precision = Math.abs(precision) precision = Math.abs(precision)
@ -82,19 +77,14 @@ export default {
let j = i.length > 3 ? i.length % 3 : 0 let j = i.length > 3 ? i.length % 3 : 0
let moneySymbol = `${symbol}` let moneySymbol = `${symbol}`
let thousandText = (j ? i.substr(0, j) + thousand_separator : '')
let amountText = i.substr(j).replace(/(\d{3})(?=\d)/g, '$1' + thousand_separator)
let precisionText = (precision ? decimal_separator + Math.abs(amount - i).toFixed(precision).slice(2) : '');
let combinedAmountText = negativeSign + thousandText + amountText + precisionText
return ( return (swap_currency_symbol
moneySymbol + ? combinedAmountText + ' ' + moneySymbol
' ' + : moneySymbol + ' ' + combinedAmountText
negativeSign +
(j ? i.substr(0, j) + thousand_separator : '') +
i.substr(j).replace(/(\d{3})(?=\d)/g, '$1' + thousand_separator) +
(precision
? decimal_separator +
Math.abs(amount - i)
.toFixed(precision)
.slice(2)
: '')
) )
} catch (e) { } catch (e) {
console.log(e) console.log(e)