Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

fix(numberFilter): correctly round fractions despite floating-point arithmetics issues in JS #7962

Merged
merged 1 commit into from
Jun 24, 2014

Conversation

IgorMinar
Copy link
Contributor

Closes #7870
Closes #7878

@mary-poppins
Copy link

Thanks for the PR! Please check the items below to help us merge this faster. See the contributing docs for more information.

  • Uses the issue template (#7962)

If you need to make changes to your pull request, you can update the commit with git commit --amend.
Then, update the pull request with git push -f.

Thanks again for your help!

@lgalfaso
Copy link
Contributor

LGTM

@lgalfaso
Copy link
Contributor

Looks I spoke too soon as it looks like there are some issues with IE10 and NaN

@caitp
Copy link
Contributor

caitp commented Jun 24, 2014

All of them, not just IE

@IgorMinar
Copy link
Contributor Author

I fixed that and pushed a new version. waiting for travis..

@lgalfaso
Copy link
Contributor

@caitp you are right

@anton000
Copy link

was about to submit a pull request. fix was:
var fraction = ('' + number.toFixed(fractionSize+1)).split(DECIMAL_SEP);

@IgorMinar
Copy link
Contributor Author

toFixed has the same issues with floating point arithmetics as regular
operators:

(1.255).toFixed(2)
=> 1.25

On Thu, Jun 26, 2014 at 6:44 AM, Anthony Chua notifications@github.com
wrote:

was about to submit a pull request. fix was:
var fraction = ('' + number.toFixed(fractionSize+1)).split(DECIMAL_SEP);


Reply to this email directly or view it on GitHub
#7962 (comment).

@anton000
Copy link

yup. i meant using the old code:

var pow = Math.pow(10, fractionSize + 1);
number = Math.floor(number * pow + 5) / pow;
var fraction = (' ' + number.toFixed(fractionSize+1)).split(DECIMAL_SEP);

fixed the problem of getting notation format on 0 with a fractionSize > 5

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

Successfully merging this pull request may close these issues.

Filter number converts 0 to 5,e-9.00000000
5 participants