From e2170466229a4093d1825f37648e113e23cad6fa Mon Sep 17 00:00:00 2001 From: Damyan Ivanov Date: Fri, 28 Jun 2019 23:13:36 +0300 Subject: [PATCH] add constructor for json.ParsedQuantity that instantiates from string fixes a reported crash --- .../net/ktnx/mobileledger/json/ParsedQuantity.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) 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; } -- 2.39.5