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

Round up returns wrong number #218

Open
takihama opened this issue Dec 5, 2024 · 1 comment
Open

Round up returns wrong number #218

takihama opened this issue Dec 5, 2024 · 1 comment

Comments

@takihama
Copy link

takihama commented Dec 5, 2024

I'm expecting the result of the roundUp to be 1.12, but it returns wrongly 1.13.

const Big = require('big.js');

const amountAvailable = 1.12;
const quantityArs = 1197.5384615384617;
const exchangeRate = 1069.2307692307693;

// Big
console.log(Big(amountAvailable).times(exchangeRate).toNumber()); // 1197.5376
console.log(Big(quantityArs).div(exchangeRate).toNumber()); // 1.12
console.log(Big(quantityArs).div(exchangeRate).round(2, Big.roundUp).toNumber()); // 1.13
console.log(Big(1.12).round(2, Big.roundUp).toNumber()); // 1.12
@MikeMcl
Copy link
Owner

MikeMcl commented Dec 5, 2024

Look first at the value of Big(quantityArs).div(exchangeRate) and then consider again whether the rounding is incorrect.

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