fix decimal

This commit is contained in:
Pham Tu 2024-01-17 18:40:43 +07:00
parent a2b4cf5c59
commit 7f4acfabe6
No known key found for this signature in database
GPG Key ID: 7460FD99133ADA1C

View File

@ -332,9 +332,16 @@ export const useFormatter = defineStore('formatter', {
return this.percent(rate);
},
percent(decimal?: string | number) {
return decimal
? numeral(decimal).divide('1000000000000000000').format('0.[00]%')
: '-';
if (!decimal) return '-';
let decimalFormat = numeral(decimal);
const decimalValue = decimalFormat.value();
if (decimalValue && decimalValue > 1e6) {
decimalFormat = decimalFormat.divide('1000000000000000000');
}
return decimalFormat.format('0.[00]%');
},
formatNumber(input?: number, fmt = '0.[00]') {
if (!input) return '';