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

四舍五入函数存在精度问题 #21

Open
GlowingRuby opened this issue Jun 7, 2022 · 1 comment
Open

四舍五入函数存在精度问题 #21

GlowingRuby opened this issue Jun 7, 2022 · 1 comment
Labels
wontfix This will not be worked on

Comments

@GlowingRuby
Copy link

https://github.com/thinkeridea/go-extend/blob/main/exmath/round.go
四舍五入函数存在精度问题,如0.565保留两位小数输出的是0.56而不是0.57

@thinkeridea
Copy link
Owner

你可能需要了解一些关于浮点数的基础知识,以下是我找到的一些资料:

https://en.wikipedia.org/wiki/IEEE_754
https://grouper.ieee.org/groups/msc/ANSI_IEEE-Std-754-2019/background/
http://c.biancheng.net/view/314.html

当前函数受浮点数算法影响,无法做到绝对的精准(浮点数本身精度并不高),只是比现有社区其它版本有所改善(精度、性能、api使用简便性),浮点数无法对精度做出保证,在较重要的数值上(例如货币)请使用更小的单位例如分进行存储和计算,展示时转换为浮点数就行展示

@thinkeridea thinkeridea added the wontfix This will not be worked on label Aug 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

2 participants