gentooboontoo / js-quantities

JavaScript library for quantity calculation and unit conversion
http://gentooboontoo.github.io/js-quantities/
MIT License
396 stars 102 forks source link

Unexpected results when dealing with unitless quantities (dividing quantities in an unsual orders) #94

Closed JoshuaCapel closed 5 years ago

JoshuaCapel commented 5 years ago

If I calculate Qty("1m").div("1km") I get a unitless 0.001 as I expected.

But if I calculate (Qty("1").div("1km")).mul("m") I get 1 m/km. Which is actually correct, but I would have expected this to just be a unitless 0.001 as above.

Also if I calculate (Qty("1").div("1km")).mul("m").mul("") I get 0.001 m2/km2. Again this is technically the correct result, but not what I would have expected.

Is this an issue with js-quantities, or are my expectations wrong?

gentooboontoo commented 5 years ago

Thanks for reporting, your expectations are right and resulting units were inconsistent. I have merged @christianp's PR #95 which has fixed the problem. I have just published a new release including it.