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

Fix number of decimal in float #76

Closed
wants to merge 1 commit into from
Closed

Fix number of decimal in float #76

wants to merge 1 commit into from

Conversation

Brtle
Copy link

@Brtle Brtle commented Sep 13, 2017

This line split a float with the . character. However, some float doesn't have a .. For instance, 1e-7 will crash.

This PR try to fix this little issue.

Value as 1e-7 wasn't working.
@YehonatanVonage
Copy link
Contributor

YehonatanVonage commented Dec 4, 2017

Hi @Brtle,
Thank you for the contribution to the "Grafana Status Panel".

TL;DR
I reject your pull request, and changing the master to fix the issue you encountered.

Description:
In javascript, decimal numbers are not represented accurate has you expect.

Try the next code:
let num = 5.56789;
let n = num.toFixed(20).replace(/^-?\d*.?|0+$/g, '')
alert(n)

Your logic fails here. Check also:
http://www.saintsatplay.com/blog/2014/08/handling-floating-point-numbers-in-javascript#.WiUlWLSZ1E4

I pushed another fix to handle your scenario in the master branch, and it will be available in the next release.

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.

2 participants