]> git.ktnx.net Git - mobile-ledger.git/blobdiff - app/src/main/java/net/ktnx/mobileledger/json/ParsedQuantity.java
whitespace
[mobile-ledger.git] / app / src / main / java / net / ktnx / mobileledger / json / ParsedQuantity.java
index 0dfc583f97f1bf61bff2da5ea566432e2ca5228a..50ce67829e9bb4ab2db7859ce4943ebc2e40b2ee 100644 (file)
@@ -25,6 +25,9 @@ public class ParsedQuantity {
     private int decimalPlaces;
     public ParsedQuantity() {
     }
+    public ParsedQuantity(String input) {
+        parseString(input);
+    }
     public long getDecimalMantissa() {
         return decimalMantissa;
     }
@@ -40,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;
+        }
+    }
 }