display amounts according to currency decimals number count

This commit is contained in:
MaysWind
2024-12-06 23:55:19 +08:00
parent e2f2b325a6
commit e549779164
15 changed files with 313 additions and 23 deletions
+11 -3
View File
@@ -44,6 +44,7 @@ export default {
'color',
'density',
'currency',
'showCurrency',
'label',
'placeholder',
'persistentPlaceholder',
@@ -100,7 +101,7 @@ export default {
return finalClass;
},
prependText() {
if (!this.currency) {
if (!this.currency || !this.showCurrency) {
return '';
}
@@ -113,7 +114,7 @@ export default {
return texts.prependText;
},
appendText() {
if (!this.currency) {
if (!this.currency || !this.showCurrency) {
return '';
}
@@ -127,6 +128,13 @@ export default {
}
},
watch: {
'currency': function () {
const newStringValue = this.getFormattedValue(this.userStore, this.modelValue);
if (!(newStringValue === '0' && this.currentValue === '')) {
this.currentValue = newStringValue;
}
},
'modelValue': function (newValue) {
const numericCurrentValue = this.$locale.parseAmount(this.userStore, this.currentValue);
@@ -300,7 +308,7 @@ export default {
getFormattedValue(userStore, value) {
if (!Number.isNaN(value) && Number.isFinite(value)) {
const digitGroupingSymbol = this.$locale.getCurrentDigitGroupingSymbol(userStore);
return removeAll(this.$locale.formatAmount(userStore, value), digitGroupingSymbol);
return removeAll(this.$locale.formatAmount(userStore, value, this.currency), digitGroupingSymbol);
}
return '0';