NSDecimal 与 Float (iOS)
我遇到过一些博客和论坛帖子,人们说在处理货币时应该使用 NSDecimalNumber 而不是浮点数。我发现我必须从 NSDecimalNumber 转换为 Floats/Doubles 才能进行一些算术,这在我看来否定了 NSDecimalNumber 的用处。我的意思是为什么不只使用浮点数而不用担心所有的转换麻烦呢?
NSDecimalNumber 有什么好处以及如何对其进行算术运算?
浮点数有而 NSDecimalNumber 没有的错误是什么,这就是为什么人们说在处理货币时必须使用 NSDecimalNumber 的原因?请量化误差?
预先感谢,
海伦。
I've come across some blogs and forum posts where people say one should use NSDecimalNumber instead of floats when dealing with currency. I find I have to convert from NSDecimalNumber to Floats/Doubles in order to do some arithmetic which in my mind negates the usefulness of NSDecimalNumber. I mean why not just use floats and not bother with all the conversions hassles?
What's the benefit of NSDecimalNumber and how do you perform arithmetic on it?
What is this error thing that floats have and NSDecimalNumber does not which is why people say one MUST use NSDecimalNumber when dealing with currencies? Please quantify the error?
Thanks in advance,
Hiren.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
类文档 有算术指令。该类是不可变的,所以看起来有点有趣。 这个问题有很好的答案,并且已接受的链接答案是关键。
The class documentation has arithmetic instructions. The class is immutable so it looks a little funny. This question has very good answers and the link in the accepted answer is key.