Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Jun 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ucum/src/main/java/systems/uom/ucum/format/UCUMFormat.java
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ private CharSequence symbolForProductUnits(ComparableUnit unit) throws IOExcepti
// add individual unit string
format(u.getKey(),sb);
// add power number if abs greater than 1
if (Math.abs(u.getValue()) < -1){
if (u.getValue() < -1){
sb.append(-u.getValue());
}
// if there is more than one denominator unit and this is the last, add close parenthesis
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@

import org.junit.jupiter.api.Test;


/**
* @author <a href="mailto:werner@uom.systems">Werner Keil</a>
*
Expand Down Expand Up @@ -396,5 +397,12 @@ public void testFormatUCUMPrintWithPositivePrefix() {

assertEquals("km/s", format.format(KILO(METER).divide(SECOND)), "The KILO prefix didn't work with a product unit");
}

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

}