Skip to content

Commit

Permalink
Issue 49500: Adjust AmountDataColumn to display only 6 decimals
Browse files Browse the repository at this point in the history
  • Loading branch information
labkey-susanh committed Jan 29, 2024
1 parent bfcf6df commit e2b35ae
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
10 changes: 10 additions & 0 deletions api/src/org/labkey/api/data/measurement/Measurement.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit e2b35ae

Please sign in to comment.