For IntelliJ IDEA,
Android Studio or Eclipse



public static Decimal one() { try { return new Decimal("1"); } catch (Exception e) { return null; // won't happen } }
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()); }
public Decimal copy() { Decimal result = new Decimal(); result.precision = precision; result.scientific = scientific; result.negative = negative; result.digits = digits; result.decimal = decimal; return result; }
@Override public Pair getCanonicalForm(Pair value) throws UcumException { assert value != null : paramError("getCanonicalForm", "value", "must not be null"); assert checkStringParam(value.getCode()) : paramError("getCanonicalForm", "value.code", "must not be null or empty"); Term term = new ExpressionParser(model).parse(value.getCode()); Canonical c = new Converter(model, handlers).convert(term); if (value.getValue() == null) return new Pair(null, new ExpressionComposer().compose(c, false)); else return new Pair(value.getValue().multiply(c.getValue()), new ExpressionComposer().compose(c, false)); }
private int countSignificants(String value) { int i = value.indexOf("."); if (i > -1) value = delete(value, i, 1); while (value.charAt(0) == '0') value = value.substring(1); return value.length(); }
private Decimal absolute() { Decimal d = copy(); d.negative = false; return d; }
public Decimal add(Decimal other) { if (other == null) return null; if (negative == other.negative) { Decimal result = doAdd(other); result.negative = negative; return result; } else if (negative) return other.doSubtract(this); else return doSubtract(other); }
private void testCompares(String v1, String v2, int outcome) throws UcumException { Decimal d1 = new Decimal(v1); Decimal d2 = new Decimal(v2); int result = d1.comparesTo(d2); check(result == outcome, "Compare fail: "+v1+".compares("+v2+") should be "+Integer.toString(outcome)+" but was "+Integer.toString(result)); }
public static Decimal zero() { try { return new Decimal("0"); } catch (Exception e) { return null; // won't happen } }