-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
swap math.round with util.formatNumber #2361
swap math.round with util.formatNumber #2361
Conversation
@@ -127,7 +127,7 @@ class ReportRenderer { | |||
this._dom.find('.leftnav-item__category', navItem).textContent = category.name; | |||
const score = this._dom.find('.leftnav-item__score', navItem); | |||
score.classList.add(`lh-score__value--${Util.calculateRating(category.score)}`); | |||
score.textContent = Math.round(Util.formatNumber(category.score)); | |||
score.textContent = Util.formatNumber(Math.round(category.score)); |
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.
Agreed about a consistent calculation of the final category score. We have a couple of places where you call Math.round(score)
.
That said, this nav score should be the same as the others. Those just use Math.round
.
Math.round(category.score)
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.
Do you want me to change it?
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.
Yes please.
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.
Done :)
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.
great catch @ev1stensberg thanks for the fix!
Fixes #2320
Previously:
formatNumber
returns a string value fromNumber.toLocaleString
, andmath.round
can't round the number.Currently:
math.round
receives an integer instead of a string, which makes the conversion complete, not returningNaN
. Note that we first domath.round
and then useformatNumber
instead of the opposite, as prior.Didn't change test for
Utils.formatNumber
, as I didn't touch it. Furthermore, I'd prefer a common conversion point for this in relation to the line I've changed, as we're basically doing the same thing. This ensures that scores are persistent and co-reliant.Before:
After: