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

Round Total Hours sum to 2 decimal precision. #850

Merged
merged 1 commit into from
Nov 14, 2018
Merged

Conversation

adunkman
Copy link
Member

Fixes #848.

We shouldn’t need anything more than 2 digits of decimal precision to calculate Total Hours. This fixes common floating point precision issues in JavaScript, most easily seen by adding 0.2 + 0.2 + 0.2 (which should result in 0.6, as shown below, but results in 0.6000000000000001 without rounding.

Screenshot showing 0.2 added three times results in 0.6

This is my first time contributing to a python project, so I’m unsure of how to write a test to cover this — let me know how, and I’d be more than happy to add (pun intended) one!

This fixes floating point math problems in JavaScript.
@tbaxter-18f
Copy link
Contributor

Thanks for this, @adunkman, and for finding the bug in the first place.

As far as I know, there aren't currently JS tests in Tock. So, if you'd like to spearhead adding those, I think we could use the help.

@tbaxter-18f tbaxter-18f merged commit f9ddfbc into master Nov 14, 2018
@rogeruiz
Copy link
Contributor

Thanks @adunkman. Writing tests for the JS in this project would require that the JavaScript be extracted outside of the HTML templates and loaded on the page as a file. Then we could have unit tests test this JS code separate of any python code.

Most of the JS in this project has been added quickly and to HTML templates. We don’t have an asset management system for external JS in the project. But this would require a refactor of most of the HTML pages among other things. Since Tock isn’t a billable project, this is probably just a good idea that may never get implemented.

@rogeruiz rogeruiz deleted the fix-float-error branch November 15, 2018 20:37
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.

Calculating sums for decimal hours isn’t correct.
3 participants