Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Print Money bug #43

Closed
jlaroca opened this issue Apr 28, 2014 · 0 comments
Closed

Print Money bug #43

jlaroca opened this issue Apr 28, 2014 · 0 comments

Comments

@jlaroca
Copy link

jlaroca commented Apr 28, 2014

Hello,

I'm using:
1)

private static final MoneyAmountStyle MONEY_AMOUNT_STYLE =
            MoneyAmountStyle.ASCII_DECIMAL_POINT_GROUP3_COMMA.withGroupingStyle(GroupingStyle.BEFORE_DECIMAL_POINT);
    
    private static final MoneyFormatter FORMATTER = new MoneyFormatterBuilder().appendAmount(MONEY_AMOUNT_STYLE).toFormatter();

Because if I use:

    private static final MoneyFormatter FORMATTER = new  MoneyFormatterBuilder().appendAmount().toFormatter();

Money with 3 decimals like BHD are printed like:

final String result=FORMATTER.print(BigMoney.of(CurrencyUnit.getInstance("BHD"), 6345345.7345345d).toMoney(RoundingMode.HALF_EVEN));

And the result is "6,345,345.735," with one final coma innecesary.

This problem is solved using 1) but in this case money with no decimals like JPY money print wrong:

String result =FORMATTER.print( BigMoney.of(CurrencyUnit.JPY, 12d).toMoney(RoundingMode.HALF_EVEN));

The result is 1212

Allways repeat the number because in AmountPrinterParser Java class in print method lines 66 and 67:

final int decPoint = str.indexOf('.');  --> This is -1 when not found.
        final int afterDecPoint = decPoint + 1;;  --> And this is 0 for not decimals values. 

Then in line 92 of same class:

 if (activeStyle.getGroupingStyle() == GroupingStyle.BEFORE_DECIMAL_POINT) {
                appendable.append(str.substring(afterDecPoint));
            }

And append all the number again because str.substring(0) = str

with result 1212.

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants