开发者

how to chop off a few decimals of a double value [duplicate]

This question already has answers here: Closed 11 years ago.

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 开发者_Go百科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!


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/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜