public Decimal(int i) { super(); try { setValueDecimal(Integer.toString(i)); } catch (Exception e) { } }
public Decimal(String value) throws UcumException { super(); value = value.toLowerCase(); if (value.contains("e")) setValueScientific(value); else setValueDecimal(value); }
/** * There are a few circumstances where a simple value is known to be correct to a high * precision. For instance, the unit prefix milli is not ~0.001, it is precisely 0.001 * to whatever precision you want to specify. This constructor allows you to specify * an alternative precision than the one implied by the stated string * * @param value - a string representation of the value * @param precision - a * @throws UcumException * @ */ public Decimal(String value, int precision) throws UcumException { super(); value = value.toLowerCase(); if (value.contains("e")) setValueScientific(value); else setValueDecimal(value); this.precision = precision; }
private void setValueScientific(String value) throws UcumException { int i = value.indexOf("e"); String s = value.substring(0, i); String e = value.substring(i+1); if (Utilities.noString(s) || s.equals("-") || !Utilities.isDecimal(s)) throw new UcumException("'"+value+"' is not a valid decimal (numeric)"); if (Utilities.noString(e) || e.equals("-") || !Utilities.isInteger(e)) throw new UcumException("'"+value+"' is not a valid decimal (exponent)"); setValueDecimal(s); scientific = true; // now adjust for exponent if (e.charAt(0) == '-') i = 1; else i = 0; while (i < e.length()) { if (!Character.isDigit(e.charAt(i))) throw new UcumException(""+value+"' is not a valid decimal"); i++; } i = Integer.parseInt(e); decimal = decimal + i; }
result.setValueDecimal(s3); } catch (Exception e) {
result.setValueDecimal(s3); } catch (Exception e) {
result.setValueDecimal(res); } catch (Exception e) {
result.setValueDecimal(r); result.decimal = r.length() - d; result.negative = negative != other.negative;
public Decimal(int i) { super(); try { setValueDecimal(Integer.toString(i)); } catch (Exception e) { } }
public Decimal(String value) throws UcumException { super(); value = value.toLowerCase(); if (value.contains("e")) setValueScientific(value); else setValueDecimal(value); }
/** * There are a few circumstances where a simple value is known to be correct to a high * precision. For instance, the unit prefix milli is not ~0.001, it is precisely 0.001 * to whatever precision you want to specify. This constructor allows you to specify * an alternative precision than the one implied by the stated string * * @param value - a string representation of the value * @param precision - a * @throws UcumException * @ */ public Decimal(String value, int precision) throws UcumException { super(); value = value.toLowerCase(); if (value.contains("e")) setValueScientific(value); else setValueDecimal(value); this.precision = precision; }
private void setValueScientific(String value) throws UcumException { int i = value.indexOf("e"); String s = value.substring(0, i); String e = value.substring(i+1); if (Utilities.noString(s) || s.equals("-") || !Utilities.isDecimal(s)) throw new UcumException("'"+value+"' is not a valid decimal (numeric)"); if (Utilities.noString(e) || e.equals("-") || !Utilities.isInteger(e)) throw new UcumException("'"+value+"' is not a valid decimal (exponent)"); setValueDecimal(s); scientific = true; // now adjust for exponent if (e.charAt(0) == '-') i = 1; else i = 0; while (i < e.length()) { if (!Character.isDigit(e.charAt(i))) throw new UcumException(""+value+"' is not a valid decimal"); i++; } i = Integer.parseInt(e); decimal = decimal + i; }
result.setValueDecimal(s3); } catch (Exception e) {
result.setValueDecimal(s3); } catch (Exception e) {
result.setValueDecimal(res); } catch (Exception e) {
result.setValueDecimal(r); result.decimal = r.length() - d; result.negative = negative != other.negative;