New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Display a count of 0 when the prep count has not been defined instead of NaN #4006
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm, I didn't look into the code too closely, but NaN is not expected result - it implies that there might be some wrong calculation going on somewhere (either division by 0, or arithmetic on non-numeric data)
please double check where NaN is coming from and correct the issue there
i.e before the calculation that could result in a NaN, add a check to guard against such case, - if such case is detected, then set 0 instead of doing the calculation
tldr: the code change you made is correct, but it is better to prevent NaN from being created rather than changing how NaN is being displayed
small thing, but also prefer using Number.isNaN over isNaN (isNaN is legacy and has some weird behavior that has been fixed in Number.isNaN)
ok will do that. The NaN comes from the fact that the count has not been defined (the field is just empty). If the user sets it to 0 we would see 0. |
f220bbd
to
b36dc73
Compare
Triggered by b36dc73 on branch refs/heads/issue-3881
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Better but not quite there. I probably wasn't clear, so let me clarify - NaN should never be created - yes, back-end returns null
, but front-end converting that to NaN is not right.
The bug occurs here:
See how line 194 uses Number.parseInt? that results in a NaN, instead, it should use f.parseInt(prepData[10] ?? undefined) ?? 0
like previous lines
for why I (and the JS community in general) are about trying to avoid NaNs as much as possible see any of the following:
- https://stackoverflow.com/questions/43580225/comparison-with-nan-doesnt-work-the-way-i-expect
- https://medium.com/codex/javascripts-nan-is-dumbass-661a3a8e8d1a
- https://ntgard.medium.com/why-nan-nan-3d41af988d30
- https://blog.webdevsimplified.com/2020-10/javascript-nan/
- https://levelup.gitconnected.com/dont-fall-into-the-nan-trap-d2fbc5536e50
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
working!
Fixes #3881