Closed dr29bart closed 4 years ago
Indriya 2.0.3 does convert the calculation results above to System Units, so the result in your example is in units of Meter. So you need to explicitely convert to Mile here ...
double distance = Quantities.getQuantity(4, USCustomary.MILE_PER_HOUR)
.to(USCustomary.MILE.divide(Units.SECOND).asType(Speed.class))
.multiply(oneSecond)
.asType(Length.class)
.to(USCustomary.MILE) // <-- explicit conversion to MILE
.getValue()
.doubleValue();
Thanks for example. The was unexpected part for me, because with it was working fine with indriya:2.0.2 and systems-common:2.0.1. Closing...
So it works as designed. Thanks @andi-huber for the quick response. I guess from the next Indriya release we might also like to provide some release notes or pointers to the Wiki etc. in such a case ;-)
I did change behavior with Indriya 2.0.3 for multiplication. So that the above use-case seemingly produces a surprising result. However, I think its strongly recommended to do calculations without assumptions about the resulting unit. An explicit conversion to the desired result type (unit) is highly recommended any way.
I will try to include this into uom-demos 2.0.1 to be released soon. Hope that's OK with everyone? We didn't do that outside systems-ucum
so far, but we'd be more than happy to also add a "contributors" file to certain parts of uom-demos
.
maven project A pom.xml (indriya:2.0.3 and systems-common:2.0.2 are included ):
project B pom.xml (only systems-common:2.0.2 is included ):
There is a main class:
Actual result: Output for the project A is: 1.78816 Output for the project B is: 0.0011111111111111111
Expected result Both projects outputs 0.0011111111111111111