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/
精彩评论