diff --git a/api/src/org/labkey/api/data/measurement/AmountDataColumn.java b/api/src/org/labkey/api/data/measurement/AmountDataColumn.java index 18381f54adc..8dfa4358ed6 100644 --- a/api/src/org/labkey/api/data/measurement/AmountDataColumn.java +++ b/api/src/org/labkey/api/data/measurement/AmountDataColumn.java @@ -80,7 +80,7 @@ private Object convertToDisplayUnits(RenderContext ctx) { Measurement.Unit storedUnit = Measurement.Unit.valueOf(ctx.get(_unitsField).toString()); if (storedUnit.isCompatible(sampleTypeUnit)) - return storedUnit.convertAmount(storedAmount, sampleTypeUnit); + return storedUnit.convertAmountForDisplay(storedAmount, sampleTypeUnit); else return storedAmount; } diff --git a/api/src/org/labkey/api/data/measurement/Measurement.java b/api/src/org/labkey/api/data/measurement/Measurement.java index f601d97d98f..2bd0439b256 100644 --- a/api/src/org/labkey/api/data/measurement/Measurement.java +++ b/api/src/org/labkey/api/data/measurement/Measurement.java @@ -1,6 +1,7 @@ package org.labkey.api.data.measurement; import org.apache.commons.lang3.StringUtils; +import org.apache.commons.math3.util.Precision; import org.jetbrains.annotations.Nullable; import org.junit.Assert; import org.junit.Test; @@ -113,6 +114,15 @@ public static Unit getUnitFromName(String name) return null; } + public Double convertAmountForDisplay(@Nullable Double amount, @Nullable Measurement.Unit targetUnit) + { + Double converted = convertAmount(amount, targetUnit); + if (converted == null) + return null; + + return Precision.round(converted, 6); + } + public Double convertAmount(@Nullable Double amount, @Nullable Measurement.Unit targetUnit) { if (amount == null)