寻找的名额双小数点后
问题说明
我有一个Double值:
I have a Double value:
double a = 4.5565;
这是什么(在这种情况下4)小数点后计算的位数的最简单的方法
What is the easiest way to calculate the number of digits after the decimal point (4 in this case).
我知道我可以转换为字符串,并做了拆分,并采取长度。但有一个更简单的方法?
I know that I can convert to string and do a split and take the length. But is there an easier way?
正确答案
有没有简单的方法,特别是数字的位数从数学上讲可能会远远超过显示。例如,4.5565实际存储为 4.556499999999999772626324556767940521240234375
(感谢哈罗德用于计算)。你不太可能找到这个问题的一个有用的解决方案。
There's no easy way, especially since the number of digits mathematically speaking might be far more than displayed. For example, 4.5565 is actually stored as 4.556499999999999772626324556767940521240234375
(thanks to harold for calculating that). You're very unlikely to find a useful solution to this problem.
修改
您的可能的想出一些算法,它的工作原理是这样的:如果你计算十进制表示,你会发现一定数量的连续787-9(或零),你圆向上(或向下)该系列787-9(或零点之前的最后的地方)开始。我怀疑你会发现更多的麻烦在这条道路比你照理。
You could come up with some algorithm that works like this: if, as you calculate the decimal representation, you find a certain number of 9s (or zeros) in succession, you round up (or down) to the last place before the series of 9s (or zeros) began. I suspect that you would find more trouble down that road than you would anticipate.
这篇好文章是转载于:学新通技术网
- 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
- 本站站名: 学新通技术网
- 本文地址: /reply/detail/tanhcebhjb
-
YouTube API 不能在 iOS (iPhone/iPad) 工作,但在桌面浏览器工作正常?
it1352 07-30 -
iPhone,一张图像叠加到另一张图像上以创建要保存的新图像?(水印)
it1352 07-17 -
保持在后台运行的 iPhone 应用程序完全可操作
it1352 07-25 -
使用 iPhone 进行移动设备管理
it1352 07-23 -
在android同时打开手电筒和前置摄像头
it1352 09-28 -
扫描 NFC 标签时是否可以启动应用程序?
it1352 08-02 -
检查邮件是否发送成功
it1352 07-25 -
Android微调工具-删除当前选择
it1352 06-20 -
使用c++17更新时出现G++编译器警告
it1352 06-18 -
复制文件夹/文件而不修改属性?
it1352 07-15