From: Damyan Ivanov Date: Sun, 22 Sep 2019 11:48:44 +0000 (+0300) Subject: factor-out parsing string as hledger's ParsedQuantity X-Git-Tag: v0.11.0~100 X-Git-Url: https://git.ktnx.net/?a=commitdiff_plain;h=1868633a2dfceef0848c85d9ed3d1d98551bbacc;p=mobile-ledger.git factor-out parsing string as hledger's ParsedQuantity the separate method can now be used for setting the object's value --- 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 600c2647..50ce6782 100644 --- a/app/src/main/java/net/ktnx/mobileledger/json/ParsedQuantity.java +++ b/app/src/main/java/net/ktnx/mobileledger/json/ParsedQuantity.java @@ -26,16 +26,7 @@ public class ParsedQuantity { 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; - } + parseString(input); } public long getDecimalMantissa() { return decimalMantissa; @@ -52,4 +43,16 @@ public class ParsedQuantity { public float asFloat() { 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.valueOf(integral); + decimalPlaces = input.length() - pointPos - 1; + } + else { + decimalMantissa = Long.valueOf(input); + decimalPlaces = 0; + } + } }