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;
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;
+ }
+ }
}