-
Notifications
You must be signed in to change notification settings - Fork 103
Open
Description
This test passes
it("should compare properly", function() {
var galQty = Qty("1 gal");
var qtQty = Qty("4 qt");
expect(galQty.eq(qtQty)).toBeTrue();
});
However, for more complex units it fails:
it("should compare properly", function() {
var galQty = Qty("1 gal/acre");
var qtQty = Qty("4 qt/acre");
expect(galQty.eq(qtQty)).toBeTrue();
});
This is due to a lack of precision. If you take a look at baseScalar in the latter test, you'll see that they're VERY close down to twenty decimal places or so, but then differ. These types of problems are generally solved by using a library like big.js, but that does mean taking on a dependency. How do you feel about that? A less-great option would be to check how close the values are in compareTo and claim that they're equal if they're "close enough" (this is how I'm working around this issue locally for now). Is there another more preferred way to solve this problem? Happy to do the legwork, just need to know what will be approved.
Metadata
Metadata
Assignees
Labels
No labels