unitsofmeasurement / uom-systems

Units of Measurement Systems
http://www.uom.systems
Other
36 stars 17 forks source link

Units with higher powers in denominator cannot be formatted with UCUM formatter #162

Closed mkostrze closed 4 years ago

mkostrze commented 4 years ago

UCUM formatter doesn't add the power number to units in denominator. As a result it incorrectly formats units like Newton - it outputs kg.m/s, or m/s2 - it outputs m/s.

Sample unit test which fails (checked 2.0 and the newest from git)

    @Test
    public void testNewton() {
        final UnitFormat format = UCUMFormat.getInstance(PRINT);
        Unit newton = KILO(UCUM.GRAM).multiply(UCUM.METER).divide(UCUM.SECOND).divide(UCUM.SECOND);
        assertEquals("kg.m/s2", format.format(newton));
    }
mkostrze commented 4 years ago

I think it's caused by the following code in UCUMFormat, compare the comment with the actual code below:

// add power number if abs greater than 1
                if (Math.abs(u.getValue()) < -1){

Patch attached.

uom-systems.patch.zip

mkostrze commented 4 years ago

Found a similar comment here:

https://github.com/unitsofmeasurement/uom-systems/issues/135#issuecomment-550207581