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

Input-Number: Fix precision problem (#15292) #15295

Merged
merged 1 commit into from
May 7, 2019
Merged

Input-Number: Fix precision problem (#15292) #15295

merged 1 commit into from
May 7, 2019

Conversation

susiwen8
Copy link
Contributor

@susiwen8 susiwen8 commented Apr 27, 2019

Please make sure these boxes are checked before submitting your PR, thank you!

  • Make sure you follow Element's contributing guide (中文 | English | Español | Français).
  • Make sure you are merging your commits to dev branch.
  • Add some descriptions and refer relative issues for you PR.

Replace toFixed() by Math.round(), because toFixed() follow Banker's Round
https://blog.csdn.net/fjnpysh/article/details/79077997

Close #15292

@element-bot
Copy link
Member

Deploy preview for element ready!

Built with commit f66edd1

https://deploy-preview-15295--element.netlify.com

@wacky6
Copy link
Contributor

wacky6 commented Apr 29, 2019

Does it really matter?

IEEE 754 float points won't correctly reflect human's definition of precision / number of decimal places anyway.

For reference:


And, JavaScript spec says nothing about Banker's Round. Please refer to ECMAScript spec instead of CSDN articles.

@susiwen8
Copy link
Contributor Author

@wacky6 Well, someone point out this issue, so for some people it matter.

I did some test in Chrome dev tool, under toFixed() case, if the number before 5 is odd it will add 1, even number won't add 1.
4.115 -> 4.12
4.125 -> 4.12
4.135 -> 4.14
4.145 -> 4.14

From ECMAScript or MDN documents, there is no prove to support 'banker's round', but I look through some example those had same problem with toFixed() precision, they all suggest to use Math.round() to avoid this problem
Screen Shot 2019-04-30 at 09 56 58

@susiwen8
Copy link
Contributor Author

susiwen8 commented May 5, 2019

Hi @wacky6 have you considered this?

@iamkun iamkun merged commit af0dc35 into ElemeFE:dev May 7, 2019
FAKER-A pushed a commit to FAKER-A/element that referenced this pull request May 7, 2019
@susiwen8 susiwen8 deleted the #15292 branch May 7, 2019 10:39
weisiren168 pushed a commit to weisiren168/element that referenced this pull request Jun 20, 2019
lzq4047 pushed a commit to lzq4047/element that referenced this pull request May 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug Report] El-input-number precision(rounding) isn't most correctly working.
4 participants