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

Fixed PR #192 (multipleOf decimal with big integer value) #193

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

linco95
Copy link

@linco95 linco95 commented Aug 16, 2022

#192

The issue seemed to be that number | 0 !== number to detect integers doesn't work for big numbers. I replaced it with the Number.isInteger function, which seems to handle all test cases quite well

Also inverted the ternary operator to avoid the negation. I also suggest replacing multipleOf.toString().split('.').pop().length with a named function

const getDecimalPart = (num) => num.toString().split(".").pop();
const getNumberOfDecimals = (num) => getDecimalPart(num).length;

var factor = Number.isInteger(multipleOf) ? 1 : Math.pow(10, getNumberOfDecimals(multipleOf))

@linco95
Copy link
Author

linco95 commented Aug 16, 2022

Closes #192

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

Successfully merging this pull request may close these issues.

None yet

2 participants