Skip to content

Commit

Permalink
Updated snapshots
Browse files Browse the repository at this point in the history
  • Loading branch information
brianacnguyen committed Dec 19, 2024
1 parent 1f2e7c6 commit a806fc2
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions app/util/number/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,7 @@ export function addCurrencySymbol(
currencyCode,
extendDecimals = false,
) {
const prefix = parseFloat(amount) < 0 ? '-' : '';
if (extendDecimals) {
if (isNumberScientificNotationWhenString(amount)) {
amount = amount.toFixed(18);
Expand Down Expand Up @@ -512,20 +513,22 @@ export function addCurrencySymbol(
amount = parseFloat(amount).toFixed(2);
}

const prefix = parseFloat(amount) < 0 ? '-' : '';
const absAmount = Math.abs(parseFloat(amount));
const amountString = amount.toString();
const absAmountStr = amountString.startsWith('-')
? amountString.slice(1) // Remove the first character if it's a '-'
: amountString;

if (currencySymbols[currencyCode]) {
return `${prefix}${currencySymbols[currencyCode]}${absAmount}`;
return `${prefix}${currencySymbols[currencyCode]}${absAmountStr}`;
}

const lowercaseCurrencyCode = currencyCode?.toLowerCase();

if (currencySymbols[lowercaseCurrencyCode]) {
return `${prefix}${currencySymbols[lowercaseCurrencyCode]}${absAmount}`;
return `${prefix}${currencySymbols[lowercaseCurrencyCode]}${absAmountStr}`;
}

return `${prefix}${absAmount} ${currencyCode}`;
return `${prefix}${absAmountStr} ${currencyCode}`;
}

/**
Expand Down

0 comments on commit a806fc2

Please sign in to comment.