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

Loss of Precision in Conversions #303

Open
nicolasmattar opened this issue Apr 25, 2019 · 0 comments
Open

Loss of Precision in Conversions #303

nicolasmattar opened this issue Apr 25, 2019 · 0 comments
Labels

Comments

@nicolasmattar
Copy link

Case:

I have a defined a new currency (BTC with 8 digits precision) and a new Exchange Provider for the Currency.

When I try to convert 1 BTC to USD, even when the exchange rate is 5489.11, the result is 5500.

Expected Result:

The conversion should return 5489.11 USD as the value 1 BTC

Possible Solution:

Maybe I am configuring something wrong, but I think the 'roundFactor' method should use the "precision" and not the "scale" to build the MathContext. (https://docs.oracle.com/javase/8/docs/api/java/math/MathContext.html)
I think this is because the library it's using the scale and MatthContext expect the Precision.

If you use scale (in this case its 2), the factor is rounded to 5.5+e3 and that is generating the wrong value.

protected NumberValue roundFactor(MonetaryAmount amount, NumberValue factor) {

Thanks.

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

No branches or pull requests

2 participants