[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Support #YMS-779947]: [udunits] ucar.units.ScaledUnit oddities



Christian,

> Consider this example Java code:
> 
> Unit metersPerSecondUnit = format.parse("m/s");
> 
> Unit unit1 = format.parse("60 m / minute");
> Unit unit2 = format.parse("600 m / 10 minutes");
> 
> System.out.println(unit1.getCanonicalString());  // Prints "1.0 m.s-1"
> System.out.println(unit2.getCanonicalString());  // Prints "3600.0 m.s"
> 
> System.out.println(metersPerSecondUnit.isCompatible(unit1));  //
> Prints "true"
> System.out.println(metersPerSecondUnit.isCompatible(unit2));  //
> Prints "false"
> 
> System.out.println(unit1.equals(unit2));  // Prints "false"
> 
> Pretty strange results, huh? Is the parse method intended to support a
> unit spec such as "600 m / 10 minutes"? It certainly didn't throw an
> exception when I tried.

The string "600 m / 10 minutes" is parsed like "((600 m) / 10) * minutes".

Use the string "(600 m) / (10 minutes)", instead.

Regards,
Steve Emmerson

Ticket Details
===================
Ticket ID: YMS-779947
Department: Support UDUNITS
Priority: Normal
Status: Closed