Skip to content

Commit

Permalink
fix: Display 0 instead of Nan (#119) (#130)
Browse files Browse the repository at this point in the history
  • Loading branch information
gromdimon authored Oct 16, 2023
1 parent d4c5e3f commit 80901c4
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions frontend/src/lib/__tests__/utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ describe.concurrent('roundIt method', () => {

it('should handle zero value', () => {
const result = roundIt(0)
expect(result).toBe("<abbr title='0'>NaN</abbr>")
expect(result).toBe("<abbr title='0'>0</abbr>")
})

it('should handle NaN value', () => {
const result = roundIt(NaN)
expect(result).toBe("<abbr title='NaN'>NaN</abbr>")
expect(result).toBe("<abbr title='NaN'>0</abbr>")
})

it('should add label to title if provided', () => {
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { DottyClient } from '@/api/dotty'
*/
export const roundIt = (value: number, digits: number = 2, label?: string): string => {
if (!value) {
return `<abbr title='${value}'>NaN</abbr>`
return `<abbr title='${value}'>0</abbr>`
}
const roundedValue = value.toFixed(digits)
const useLabel = label ? `${label}: ` : ''
Expand Down

0 comments on commit 80901c4

Please sign in to comment.