Skip to content

Commit 63031ee

Browse files
committed
add fast path for unit conversion
1 parent 4a886ae commit 63031ee

File tree

2 files changed

+3
-0
lines changed

2 files changed

+3
-0
lines changed

core/src/androidTest/java/io/snabble/sdk/UnitTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ public void testUnitPrices() throws IOException, Snabble.SnabbleException {
2828
Assert.assertEquals(199, test_cm_1.getPrice());
2929
Assert.assertEquals(1990, test_cm_1.getPriceForQuantity(1000, RoundingMode.HALF_UP));
3030
Assert.assertEquals(498, test_cm_1.getPriceForQuantity(250, RoundingMode.HALF_UP));
31+
Assert.assertEquals(497, test_cm_1.getPriceForQuantity(250, RoundingMode.FLOOR));
3132
}
3233

3334
public void testUnits() {

core/src/main/java/io/snabble/sdk/Unit.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ public static Unit fromString(String value) {
5151
}
5252

5353
public static BigDecimal convert(BigDecimal value, Unit from, Unit to, int scale, RoundingMode rm) {
54+
if (from == to) return value;
55+
5456
value = value.setScale(scale, rm);
5557

5658
if (from == LITER && to == DECILITER) return value.divide(new BigDecimal(10), rm);

0 commit comments

Comments
 (0)