Skip to content
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

Merged
merged 2 commits into from
May 25, 2017
Merged

swap math.round with util.formatNumber #2361

merged 2 commits into from
May 25, 2017

Conversation

evenstensberg
Copy link
Contributor

Fixes #2320

Previously:

formatNumber returns a string value from Number.toLocaleString, and math.round can't round the number.

Currently:

math.round receives an integer instead of a string, which makes the conversion complete, not returning NaN. Note that we first do math.round and then use formatNumber 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:

skjermbilde 2017-05-25 kl 11 06 01
skjermbilde 2017-05-25 kl 11 07 41

After:

skjermbilde 2017-05-25 kl 10 59 27

skjermbilde 2017-05-25 kl 11 10 22

@evenstensberg evenstensberg changed the title swap math.round & util.formatNum swap math.round & util.formatNumber May 25, 2017
@evenstensberg evenstensberg changed the title swap math.round & util.formatNumber swap math.round with util.formatNumber May 25, 2017
@@ -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));
Copy link
Contributor

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)

Copy link
Contributor Author

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?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes please.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done :)

Copy link
Collaborator

@patrickhulce patrickhulce left a 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!

@ebidel ebidel merged commit 2c96546 into GoogleChrome:master May 25, 2017
@evenstensberg evenstensberg deleted the fix-round-conversion branch May 25, 2017 21:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants