Skip to content

Commit

Permalink
update trimDecimalZeros function
Browse files Browse the repository at this point in the history
  • Loading branch information
p6te committed Oct 29, 2024
1 parent 82988ed commit 652b5d4
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1478,13 +1478,16 @@ export const trimDecimalZeros = (numStr: string): string => {
const withoutTrailingDot = numStr.replace(/\.$/, '')

if (!withoutTrailingDot.includes('.')) {
return withoutTrailingDot
return withoutTrailingDot.replace(/^0+/, '') || '0'
}

const [integerPart, decimalPart] = withoutTrailingDot.split('.')

const trimmedDecimal = decimalPart.replace(/0+$/, '')
return trimmedDecimal ? `${integerPart}.${trimmedDecimal}` : integerPart

const trimmedInteger = integerPart.replace(/^0+/, '')

return trimmedDecimal ? `${trimmedInteger || '0'}.${trimmedDecimal}` : trimmedInteger || '0'
}

export const stringToFixed = (string: string, numbersAfterDot: number): string => {
Expand Down

0 comments on commit 652b5d4

Please sign in to comment.