如何截去双精度值的几位小数
可能的重复:
从双精度数据获取特定整数的方法类型
C++
所以我需要一种方法来从双精度 56.279 或任何其他整数中获取数字 7,并且如果不知道数字 7 是什么,我无法弄清楚如何做到这一点双倍返回自我的函数是(所以我不能简单地做 56.279 - .009)。
我的函数总是以这种形式返回经过的秒数作为双精度值:000.000。我也只有 5 个字符空间来将时间打印到 CONSOLE 窗口,因此
如果数字小于 10,我只需打印 0.000 秒,如果超过 10 00.00,如果超过 60 秒(一分钟)然后 0:00,最后如果超过 10 分钟,我将在 5 个字符空间中打印 00:00。因此,我需要去掉 56.279 中的 9,以便该数字适合空格。我想我需要简单地单独获取除 9 之外的每个数字并将它们插入到 char 数组中...
还有其他想法吗?
谢谢!
Possible Duplicate:
way to get specific integer(s) from a double data type
C++
So i need a way to get say the number 7 from the double 56.279 or any other of the integers and i cannot figure out how to do it without having the knowledge of what the double returned from my function is going to be (so i cant simply do 56.279 - .009).
My function alway returns seconds elapsed as a double in this form: 000.000. I also only have 5 character spaces to print the time to the CONSOLE window so
if the number is less than ten i need to simply print 0.000 sec, if more than ten 00.00, if more than sixty seconds (one minute) then 0:00, and finally if more than 10 minutes i will print 00:00 in the 5 character space. I need to therefore get rid of the 9 in the 56.279 so the number fits in the space. I'm thinking i need to simply get each number individually except for 9 and insert them into a char array...
Any other ideas?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看看这个页面:
http://www.cplusplus.com/reference/iostream/ios_base/ precision/
如果您只需要更改显示,类似 setw 的内容可能合适:
http://www.cplusplus.com/reference/iostream/manipulators/setw/
Look at this page:
http://www.cplusplus.com/reference/iostream/ios_base/precision/
If you only need to change the display something like setw might appropriate:
http://www.cplusplus.com/reference/iostream/manipulators/setw/