/** * Returns the smalles positive value.<br> * Ex.: if scale is 2 --> 0.01 will be returned. * * @return the smalles positive value */ public BMoney smallestPositive() { return new BMoney(new BigDecimal(new BigInteger(new byte[] { 1 })).movePointLeft(scale())); }
/** * Inverts this money value. * * @return the negated money value */ public BMoney invert() { return new BMoney(unscaledValue().negate(), scale()); }
/** * Multiplies this BMoney by a double and returns a new object. * This object remains unchanged. * * @param val the double to multiply with * @return the product of this and given value */ public BMoney multiply(double val) { return new BMoney(doubleValue() * val, scale()); }
/** * Divides a BMoney by double and returns a new object. * This object remains unchanged. * * @param val the value to divide this BMoney by * @return the quotient of this and given value */ public BMoney divide(double val) { return new BMoney(doubleValue() / val, scale()); }
/** * Adds a BMoney to this value and returns a new object. * This object remains unchanged. * * @param val the money value to add * @return the sum of this and given value */ public BMoney add(BMoney val) { return new BMoney(unscaledValue().add(alignScale(val).unscaledValue()), scale()); }
/** * Subtracts a BMoney from this value and returns a new object. * This object remains unchanged. * * @param val the money value to subtract * @return this minus the given value */ public BMoney subtract(BMoney val) { return new BMoney(unscaledValue().subtract(alignScale(val).unscaledValue()), scale()); }
/** * Retrieves the value of the designated column in the current row * of this <code>ResultSet</code> object as a * <code>BMoney</code> with full precision.<br> * Notice that BMoney fields use two fields: * one for the value and * one for the scale (= name + "_2") * * @param name the label for the column specified with the SQL AS clause. If the SQL AS clause was not specified, then the label is the name of the column * @return the column value (full precision); * if the value is SQL <code>NULL</code>, the value returned is * <code>null</code> in the Java programming language. */ public BMoney getBMoney (String name) { double value = getDouble(name); return wasNull() ? null : new BMoney (value, getInt(name + "_2")); }
return new BMoney(value, FormatHelper.determineScale(value));
/** * Retrieves the value of the designated column in the current row * of this <code>ResultSet</code> object as a * <code>BMoney</code> with full precision.<br> * Notice that BMoney fields use two fields: * one for the value and * one for the scale (= name + "P") * * @param pos the parameter index for the amount in the result set * @param ppos the parameter index for the scale in the result set * @return the column value (full precision); * if the value is SQL <code>NULL</code>, the value returned is * <code>null</code> in the Java programming language. */ public BMoney getBMoney (int pos, int ppos) { double value = getDouble(pos); return wasNull() ? null : new BMoney (value, getInt(ppos)); }
/** * Check the scale of the given money value. * If it does not match the scale of this object, * scale it to the current scale of this object. * * @param val the value to be checked * @return the re-scaled value or the value itself if no rescaling necessary */ protected BMoney alignScale(BMoney val) { return val.scale() == scale() ? val : new BMoney(val.unscaledValue(), scale()); }
/** * Creates a money print label. * * @param columns the width in columns, 0 = minimum width */ public BMoneyPrintLabel (int columns) { super (columns); // generate default format format.setGroupingUsed(true); format.setGroupingSize(3); format.applyPattern(FormatHelper.getMoneyPattern()); setScale(Currency.getInstance(LocaleProvider.getInstance().getLocale()).getDefaultFractionDigits()); setPrintValue(new BMoney()); }
money = new BMoney(value);
/** * Retrieves the value of the designated column in the current row * of this <code>ResultSet</code> object as a * <code>BMoney</code> with full precision.<br> * Notice that BMoney fields use two fields: * one for the value and * one for the scale (= name + "P") * * @return the column value (full precision); * if the value is SQL <code>NULL</code>, the value returned is * <code>null</code> in the Java programming language. */ public BMoney getBMoney () { double value = getDouble(nextConfiguredIndex()); return wasNull() ? null : new BMoney (value, getInt(nextConfiguredIndex())); }
money = new BMoney(value);