public Decimal copy() { Decimal result = new Decimal(); result.precision = precision; result.scientific = scientific; result.negative = negative; result.digits = digits; result.decimal = decimal; return result; }
public static Decimal zero() { try { return new Decimal("0"); } catch (Exception e) { return null; // won't happen } }
public static Decimal one() { try { return new Decimal("1"); } catch (Exception e) { return null; // won't happen } }
public void divideValue(int divisor) throws UcumException { value = value.divide(new Decimal(divisor)); }
public void multiplyValue(int multiplicand) { value = value.multiply(new Decimal(multiplicand)); }
private Pair qtyToPair(Quantity q) { if (!"http://unitsofmeasure.org".equals(q.getSystem())) return null; try { return new Pair(new Decimal(q.getValue().toPlainString()), q.getCode()); } catch (UcumException e) { return null; } }
private Value parseValue(XmlPullParser xpp, String context) throws XmlPullParserException, UcumException, IOException { checkAtElement(xpp, "value", context); Decimal val = null; if (xpp.getAttributeValue(null, "value") != null) try { if (xpp.getAttributeValue(null, "value").contains(".")) val = new Decimal(xpp.getAttributeValue(null, "value"), 24); // unlimited precision for these else val = new Decimal(xpp.getAttributeValue(null, "value")); } catch (NumberFormatException e) { throw new XmlPullParserException("Error reading "+context+": "+e.getMessage()); } Value value = new Value(xpp.getAttributeValue(null, "Unit"), xpp.getAttributeValue(null, "UNIT"), val); value.setText(readElement(xpp, "value", context, true)); return value; }
Decimal result = new Decimal(); try { result.setValueDecimal(s3);
Decimal result = new Decimal(); try { result.setValueDecimal(s3);
private DecimalType qtyToCanonical(Quantity q) { if (!"http://unitsofmeasure.org".equals(q.getSystem())) return null; try { Pair p = new Pair(new Decimal(q.getValue().toPlainString()), q.getCode()); Pair c = worker.getUcumService().getCanonicalForm(p); return new DecimalType(c.getValue().asDecimal()); } catch (UcumException e) { return null; } }
public int asInteger() throws UcumException { if (!isWholeNumber()) throw new UcumException("Unable to represent "+toString()+" as an integer"); if (comparesTo(new Decimal(Integer.MIN_VALUE)) < 0) throw new UcumException("Unable to represent "+toString()+" as a signed 8 byte integer"); if (comparesTo(new Decimal(Integer.MAX_VALUE)) > 0) throw new UcumException("Unable to represent "+toString()+" as a signed 8 byte integer"); return Integer.parseInt(asDecimal()); }
private Prefix parsePrefix(XmlPullParser xpp) throws XmlPullParserException, IOException, UcumException { Prefix prefix = new Prefix(xpp.getAttributeValue(null, "Code"), xpp.getAttributeValue(null, "CODE")); xpp.next(); skipWhitespace(xpp); prefix.getNames().add(readElement(xpp, "name", "prefix "+prefix.getCode(), false)); prefix.setPrintSymbol(readElement(xpp, "printSymbol", "prefix "+prefix.getCode(), false)); checkAtElement(xpp, "value", "prefix "+prefix.getCode()); prefix.setValue(new Decimal(xpp.getAttributeValue(null, "value"), 24)); readElement(xpp, "value", "prefix "+prefix.getCode(), true); xpp.next(); skipWhitespace(xpp); return prefix; }
res = delete(res, res.length()-1, 1); Decimal result = new Decimal(); try { result.setValueDecimal(res);
private Canonical normalise(String indent, Symbol sym) throws UcumException { Canonical result = new Canonical(new Decimal(1)); if (sym.getUnit() instanceof BaseUnit) { result.getUnits().add(new CanonicalUnit((BaseUnit) sym.getUnit(), sym.getExponent())); } else { Canonical can = expandDefinedUnit(indent, (DefinedUnit) sym.getUnit()); for (CanonicalUnit c : can.getUnits()) { c.setExponent(c.getExponent() * sym.getExponent()); } result.getUnits().addAll(can.getUnits()); if (sym.getExponent() > 0) for (int i = 0; i < sym.getExponent(); i++) result.multiplyValue(can.getValue()); else for (int i = 0; i > sym.getExponent(); i--) result.divideValue(can.getValue()); } if (sym.getPrefix() != null) { if (sym.getExponent() > 0) for (int i = 0; i < sym.getExponent(); i++) result.multiplyValue(sym.getPrefix().getValue()); else for (int i = 0; i > sym.getExponent(); i--) result.divideValue(sym.getPrefix().getValue()); } return result; }
private Canonical normalise(String indent, Term term) throws UcumException { Canonical result = new Canonical(new Decimal(1));
private void init() { register(new CelsiusHandler()); register(new FahrenheitHandler()); register(new HoldingHandler("[p'diop]", "deg")); register(new HoldingHandler("%[slope]", "deg")); register(new HoldingHandler("[hp_X]", "1")); register(new HoldingHandler("[hp_C]", "1")); register(new HoldingHandler("[pH]", "mol/l")); register(new HoldingHandler("Np", "1")); register(new HoldingHandler("B", "1")); register(new HoldingHandler("B[SPL]", "10*-5.Pa", new Decimal(2))); register(new HoldingHandler("B[V]", "V")); register(new HoldingHandler("B[mV]", "mV")); register(new HoldingHandler("B[uV]", "uV")); register(new HoldingHandler("B[W]", "W")); register(new HoldingHandler("B[kW]", "kW")); register(new HoldingHandler("bit_s", "1")); }