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

Trailing zero / compareTo bug? #5

Open
markstreich opened this issue Aug 3, 2012 · 4 comments
Open

Trailing zero / compareTo bug? #5

markstreich opened this issue Aug 3, 2012 · 4 comments

Comments

@markstreich
Copy link

Hi, using both nodejs and in the browser (firefox and chrome), I'm not getting the expected result for compareTo of 'equal' values, one with trailing zeros.

I thought compareTo ignored scale? Maybe I'm missing something though?

For now I'm adding .stripTrailingZeros() for each side of compareTo calls as a workaround.

Example:

var BD = require("bigdecimal");
var a=BD.BigDecimal('0.09');
var b=a.setScale(4);
console.log(a.compareTo(b)); // returns 1 (expected 0)
var a=BD.BigDecimal('0.091');
var b=BD.BigDecimal('0.0910000');
console.log(a.compareTo(b)); // returns 1 (expected 0)
@leehankyeol
Copy link

Wow I've just found this bug and it's... old.

@JasonGiedymin
Copy link

I think you want to compare tostring representations instead.

@leehankyeol
Copy link

@JasonGiedymin I decided to move on to big.js, which is well maintained by now.

@JasonGiedymin
Copy link

@leehankyeol ya your right, long time ago (you can search my projects) I moved to https://github.com/substack/node-bigint. This lib didn’t work for me. Can vouch that the lib I went to was validated against other bigint classes (I.e Java, also in my public projects).

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

3 participants