From: Damyan Ivanov Date: Fri, 28 Jun 2019 20:13:36 +0000 (+0300) Subject: add constructor for json.ParsedQuantity that instantiates from string X-Git-Tag: v0.10.3~2 X-Git-Url: https://git.ktnx.net/?a=commitdiff_plain;h=e2170466229a4093d1825f37648e113e23cad6fa;p=mobile-ledger.git add constructor for json.ParsedQuantity that instantiates from string fixes a reported crash --- diff --git a/app/src/main/java/net/ktnx/mobileledger/json/ParsedQuantity.java b/app/src/main/java/net/ktnx/mobileledger/json/ParsedQuantity.java index 0dfc583f..600c2647 100644 --- a/app/src/main/java/net/ktnx/mobileledger/json/ParsedQuantity.java +++ b/app/src/main/java/net/ktnx/mobileledger/json/ParsedQuantity.java @@ -25,6 +25,18 @@ public class ParsedQuantity { private int decimalPlaces; public ParsedQuantity() { } + public ParsedQuantity(String input) { + int pointPos = input.indexOf('.'); + if (pointPos >= 0) { + String integral = input.replace(".", ""); + decimalMantissa = Long.valueOf(integral); + decimalPlaces = input.length() - pointPos - 1; + } + else { + decimalMantissa = Long.valueOf(input); + decimalPlaces = 0; + } + } public long getDecimalMantissa() { return decimalMantissa; }