Make QuantityType.toUnitRelative accept a String (#3802)

Signed-off-by: Jimmy Tanagra <jcode@tanagra.id.au>
This commit is contained in:
jimtng 2023-10-07 04:42:50 +10:00 committed by GitHub
parent fb3d4e805d
commit 0d355fbbc7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -338,6 +338,15 @@ public class QuantityType<T extends Quantity<T>> extends Number
return new QuantityType<>(result.getValue(), targetUnit);
}
public @Nullable QuantityType<T> toUnitRelative(String targetUnit) {
Unit<T> unit = (Unit<T>) AbstractUnit.parse(targetUnit);
if (unit != null) {
return toUnitRelative(unit);
}
return null;
}
public BigDecimal toBigDecimal() {
return new BigDecimal(quantity.getValue().toString());
}