mirror of
https://github.com/mayswind/ezbookkeeping.git
synced 2026-05-19 17:24:26 +08:00
display amounts according to currency decimals number count
This commit is contained in:
@@ -146,6 +146,11 @@ export function formatAmount(value, options) {
|
||||
}
|
||||
|
||||
const decimalSeparator = options.decimalSeparator || numeralConstants.defaultDecimalSeparator.symbol;
|
||||
let decimalNumberCount = options.decimalNumberCount;
|
||||
|
||||
if (!isNumber(decimalNumberCount) || decimalNumberCount > numeralConstants.maxSupportedDecimalNumberCount) {
|
||||
decimalNumberCount = numeralConstants.defaultDecimalNumberCount;
|
||||
}
|
||||
|
||||
let integer = '0';
|
||||
let decimals = '00';
|
||||
@@ -159,6 +164,18 @@ export function formatAmount(value, options) {
|
||||
decimals = '0' + value;
|
||||
}
|
||||
|
||||
if (decimalNumberCount === 0) {
|
||||
if (decimals === '00') {
|
||||
decimals = '';
|
||||
} else if (decimals.charAt(1) === '0') {
|
||||
decimals = decimals.charAt(0);
|
||||
}
|
||||
} else if (decimalNumberCount === 1) {
|
||||
if (decimals.charAt(1) === '0') {
|
||||
decimals = decimals.charAt(0);
|
||||
}
|
||||
}
|
||||
|
||||
if (options.trimTailZero) {
|
||||
if (decimals.charAt(0) === '0' && decimals.charAt(1) === '0') {
|
||||
decimals = '';
|
||||
@@ -194,6 +211,16 @@ export function formatPercent(value, precision, lowPrecisionValue) {
|
||||
return result + '%';
|
||||
}
|
||||
|
||||
export function getAmountWithDecimalNumberCount(amount, decimalNumberCount) {
|
||||
if (decimalNumberCount === 0) {
|
||||
return Math.floor(amount / 100) * 100;
|
||||
} else if (decimalNumberCount === 1) {
|
||||
return Math.floor(amount / 10) * 10;
|
||||
}
|
||||
|
||||
return amount;
|
||||
}
|
||||
|
||||
export function formatExchangeRateAmount(exchangeRateAmount, options) {
|
||||
if (!options) {
|
||||
options = {};
|
||||
|
||||
Reference in New Issue
Block a user