]> git.ktnx.net Git - mobile-ledger.git/blobdiff - app/src/main/java/net/ktnx/mobileledger/json/ParsedQuantity.java
add support for hledger-web 1.23 json schema
[mobile-ledger.git] / app / src / main / java / net / ktnx / mobileledger / json / ParsedQuantity.java
index 600c26474d73f58fac6018c28d425a09575b9057..2068479508188980f3aab1a7b05ca510c58214b0 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright © 2019 Damyan Ivanov.
+ * Copyright © 2020 Damyan Ivanov.
  * This file is part of MoLe.
  * MoLe is free software: you can distribute it and/or modify it
  * under the term of the GNU General Public License as published by
@@ -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.parseLong(integral);
+            decimalPlaces = input.length() - pointPos - 1;
+        }
+        else {
+            decimalMantissa = Long.parseLong(input);
+            decimalPlaces = 0;
+        }
+    }
 }