-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Fix math in InventoryPurchaseItem.costPerUnit and add math util for rounding #864
Fix math in InventoryPurchaseItem.costPerUnit and add math util for rounding #864
Conversation
- Add unit model test inv-purchase InventoryPurchaseItem
- Fix incorrect calculation `InventoryPurchaseItem.costPerUnit` to round property to the nearest 100th - Add test for demostrating issue in `inv-purchase-test.js` "costPerUnit properly round" - Add math util with function `round100` - Add tests for `round100` function
Using It is possible that this is not the only place this issue exists. I haven't looked for other spots as I wanted to make sure this was an acceptable solution going forward. It may also be a better choice to instead bring in a library specifically designed to handle JavaScript's various math quirks. The advantage is that it would likely handle further edge cases than our internal implementations. The disadvantage is that is adds one more library to maintain and increases the overall download size of the application. Edit: Typo in rounds to result |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mkly thanks for the PR. I would prefer to update the mixin https://github.com/HospitalRun/hospitalrun-frontend/blob/master/app/mixins/number-format.js to handle this rounding error and then use that mixin vs the toFixed(2)
Sounds good. Will do. Thanks |
- Fix rounding in `_numberFormat` for number-format mixin - Add mixin unit tests for number-format mixin
- Use `NumberFormat` mixin for `InventoryPurchaseItem` and use in `costPerUnit` method - Remove math util as no longer needed
Barring any CI issues this should be ready for review. Hopefully I understood you correctly in the use of the mixin here. I went ahead and added a little test coverage for NumberFormat while I was in there. Thanks again for taking the time for the review. Still learning my way around the code base and getting up to speed with the preferred conventions. 🍹 |
Also, let me know if you want me to squash these commits down and open a new PR for merging |
Looks good to me @mkly! I can squash the commits here on GitHub. |
Fixes math in InventoryPurchaseItem.costPerUnit and add math util for rounding
Changes proposed in this pull request:
InventoryPurchaseItem.costPerUnit
to roundproperty to the nearest 100th
inv-purchase-test.js
"costPerUnit properly round"
round100
round100
functioncc @HospitalRun/core-maintainers