unitsofmeasurement/uom-systems

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

Closed this issue · 2 comments

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));
    }

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

Found a similar comment here:

#135 (comment)