feat(utils-format-number): fixed number

This commit is contained in:
RadoslavDimchev 2024-03-08 08:08:11 +02:00 committed by Emil Ivanichkov
parent 2e17c53415
commit 9e49826b25
1 changed files with 3 additions and 1 deletions

View File

@ -28,7 +28,9 @@ export const convertSecondsToTimerFormat = (seconds: number) => {
}
export const formatNumbersWithComa = (n: number): string => {
const parts = n.toString().split('.')
const isWholeNumber = n % 1 === 0
const numberString = isWholeNumber ? n.toString() : n.toFixed(2)
const parts = numberString.split('.')
parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ',')
return parts.join('.')
}