Vonage / Grafana_Status_panel

A panel plugin for Grafana to monitor multiple parameters at once
Other
179 stars 108 forks source link

Fix number of decimal in float #76

Closed Brtle closed 6 years ago

Brtle commented 7 years ago

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.

YehonatanVonage commented 6 years ago

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.