unitsofmeasurement / indriya

JSR 385 - Reference Implementation
Other
115 stars 40 forks source link

SQUARE_METRE conversion to KILO(Units.SQUARE_METRE)) is incorrect #319

Closed babubabu closed 3 years ago

babubabu commented 3 years ago

Hi,

if I run a conversion from m² to km², I would expect the value to be multiplied with 10^-6, but its just multiplied with 10^-3

So if I ran: Quantities.getQuantity(1000, Units.SQUARE_METRE).to(MetricPrefix.KILO(Units.SQUARE_METRE)) I would expect a Quantity like this: Quantities.getQuantity(0.001, MetricPrefix.KILO(Units.SQUARE_METRE)) what I currently get is:

Quantities.getQuantity(1, MetricPrefix.KILO(Units.SQUARE_METRE)) Used Version: 2.1.1

If you need more inforamations, please let me know.

andi-huber commented 3 years ago

Note: kilo(m²) is not the same as (kilo(m))² ... with above code you are doing the former

For convenience you'd need to define your own product unit say SQUARE_KILO_METRE.

So I'd say this is not an issue.

babubabu commented 3 years ago

You're completly right. Thanks for your fast help!

Please close that issue.

Is that a point for some docs or a example test?

andi-huber commented 3 years ago

import javax.measure.MetricPrefix;
import javax.measure.Unit;
import javax.measure.quantity.Area;
import tech.units.indriya.unit.ProductUnit;
import tech.units.indriya.unit.Units;

...

Unit<Area> SQUARE_KILO_METRE = 
            new ProductUnit<>(
                    MetricPrefix.KILO(Units.METRE).multiply(MetricPrefix.KILO(Units.METRE)))
            .asType(Area.class);
babubabu commented 3 years ago

Thanks a lot. I missed the last asType()