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

Rounding Issue #9

Open
GutHib opened this issue Mar 15, 2013 · 2 comments
Open

Rounding Issue #9

GutHib opened this issue Mar 15, 2013 · 2 comments

Comments

@GutHib
Copy link

GutHib commented Mar 15, 2013

Seems like converting 100 units of one currency to itself will not always result in 100 units. Example:

fx.base = "USD";
fx.rates = {
"EUR" : 1.745101,
}

Result: Converting 100 EUR to EUR will actually result in 99.9999999999.

Is this something that will be fixed in the library, or do I need to figure out how to do it in my script? (I'm afraid I'm not exactly a js buff, hence the question.)

Thanks!

@minopret
Copy link

Unless you employ something like String or github.com/dtrebbien/BigDecimal.js instead of a JavaScript number (IEEE 754 double-precision, 64 bits in total with 52 bits (=13 hex digits) for fractional part of the value), you'll have round-off. In particular when you want one cent and JavaScript stores the amount as 0.01 = (+2^-7)(1+(47ae147ae147ae1 base 16)/(16^15 - 1)), you're really storing the approximation (+2^-7)(1+(47ae147ae147a base 16)/16^13) = 0.0099999999999999984734433411404097569175064563751220703125

@GutHib
Copy link
Author

GutHib commented Mar 19, 2013

Thanks for the explanation. I'm now rounding the results in javascript (easy enough, even for me ;).

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

No branches or pull requests

2 participants