swap math.round with util.formatNumber#2361
Merged
ebidel merged 2 commits intoGoogleChrome:masterfrom May 25, 2017
evenstensberg:fix-round-conversion
Merged
swap math.round with util.formatNumber#2361ebidel merged 2 commits intoGoogleChrome:masterfrom evenstensberg:fix-round-conversion
ebidel merged 2 commits intoGoogleChrome:masterfrom
evenstensberg:fix-round-conversion
Conversation
ebidel
reviewed
May 25, 2017
| 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)); |
Contributor
There was a problem hiding this comment.
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)
Contributor
Author
There was a problem hiding this comment.
Do you want me to change it?
ebidel
approved these changes
May 25, 2017
patrickhulce
approved these changes
May 25, 2017
Collaborator
patrickhulce
left a comment
There was a problem hiding this comment.
great catch @ev1stensberg thanks for the fix!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2320
Previously:
formatNumberreturns a string value fromNumber.toLocaleString, andmath.roundcan't round the number.Currently:
math.roundreceives an integer instead of a string, which makes the conversion complete, not returningNaN. Note that we first domath.roundand then useformatNumberinstead 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: