From f46c876dcda0477c4619ef690fa0b7a480d9d8e3 Mon Sep 17 00:00:00 2001 From: Damyan Ivanov Date: Tue, 29 Sep 2020 15:27:24 +0000 Subject: [PATCH] Revert "add support for floatingPoint member of the quantity objects" This reverts commit d6d15ebf2287b3e9d7c213241367ef053e971e60. The problem with that is that it breaks sending new transactions for older versions of hledger-web. It is also not really necessary, because the precision got limited so that there is no longer possible to get 255 decimal digits for periodic results --- .../json/v1_14/ParsedQuantity.java | 4 +- .../json/v1_15/ParsedQuantity.java | 44 +++++++++++++------ 2 files changed, 33 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/net/ktnx/mobileledger/json/v1_14/ParsedQuantity.java b/app/src/main/java/net/ktnx/mobileledger/json/v1_14/ParsedQuantity.java index 2588054f..5c27f6fb 100644 --- a/app/src/main/java/net/ktnx/mobileledger/json/v1_14/ParsedQuantity.java +++ b/app/src/main/java/net/ktnx/mobileledger/json/v1_14/ParsedQuantity.java @@ -21,8 +21,8 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; @JsonIgnoreProperties(ignoreUnknown = true) public class ParsedQuantity { - protected long decimalMantissa; - protected int decimalPlaces; + private long decimalMantissa; + private int decimalPlaces; public ParsedQuantity() { } public ParsedQuantity(String input) { diff --git a/app/src/main/java/net/ktnx/mobileledger/json/v1_15/ParsedQuantity.java b/app/src/main/java/net/ktnx/mobileledger/json/v1_15/ParsedQuantity.java index 7ce1d12d..f4096830 100644 --- a/app/src/main/java/net/ktnx/mobileledger/json/v1_15/ParsedQuantity.java +++ b/app/src/main/java/net/ktnx/mobileledger/json/v1_15/ParsedQuantity.java @@ -20,21 +20,39 @@ package net.ktnx.mobileledger.json.v1_15; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; @JsonIgnoreProperties(ignoreUnknown = true) -public class ParsedQuantity extends net.ktnx.mobileledger.json.v1_14.ParsedQuantity { - private float floatingPoint; - private boolean floatingPointSet = false; - public float getFloatingPoint() { - if (!floatingPointSet) - throw new IllegalStateException("floatingPoint is not set"); - return floatingPoint; - } - public void setFloatingPoint(float floatingPoint) { - this.floatingPoint = floatingPoint; - floatingPointSet = true; +public class ParsedQuantity { + private long decimalMantissa; + private int decimalPlaces; + public ParsedQuantity() { + } + public ParsedQuantity(String input) { + parseString(input); + } + public long getDecimalMantissa() { + return decimalMantissa; + } + public void setDecimalMantissa(long decimalMantissa) { + this.decimalMantissa = decimalMantissa; + } + public int getDecimalPlaces() { + return decimalPlaces; + } + public void setDecimalPlaces(int decimalPlaces) { + this.decimalPlaces = decimalPlaces; } public float asFloat() { - if (floatingPointSet) - return floatingPoint; return (float) (decimalMantissa * Math.pow(10, -decimalPlaces)); } + public void parseString(String input) { + int pointPos = input.indexOf('.'); + if (pointPos >= 0) { + String integral = input.replace(".", ""); + decimalMantissa = Long.parseLong(integral); + decimalPlaces = input.length() - pointPos - 1; + } + else { + decimalMantissa = Long.parseLong(input); + decimalPlaces = 0; + } + } } -- 2.39.2