/** * Creates a BMoney from a BMoney (useful to rescale) * * @param val the BMoney value * @param scale the digits after comma the value should be rounded to */ public BMoney (BMoney val, int scale) { super(val.setScale(scale, RoundingMode.HALF_UP).unscaledValue(), scale); }
/** * Converts a money value to a string of digits as words.<br> * The digits after the comma are ignored. * Nice to print checks. * <pre> * Example: 234,77 will become "two three four" * </pre> * * @return the value as a words */ public String toWords() { String digits = setScale(0, RoundingMode.DOWN).toString(); int len = digits.length(); StringBuilder buf = new StringBuilder(); boolean first = true; for (int i=0; i < len; i++) { char c = digits.charAt(i); if (Character.isDigit(c)) { if (first) { first = false; } else { buf.append(' '); } buf.append(StringHelper.digitToString(c)); } } return buf.toString(); }