方式从双数据类型获取特定的整数 [英] way to get specific integer(s) from a double data type

查看:108
本文介绍了方式从双数据类型获取特定的整数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

C ++

所以我需要一种方法来从双56.279或任何其他整数得到数7,找出如何做,而不知道从我的函数返回的双方是什么(所以我不能只做56.279 - .009)。

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).

我的功能总是返回已过秒数作为双精度形式:000.000。我也只有5个字符空格打印时间到 CONSOLE窗口,所以

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

如果数字小于十我需要简单打印0.000秒,如果超过十个00.00,如果超过六十秒(一分钟)然后0:00,最后如果超过10分钟我将在5个字符空间打印00:00。我需要因此摆脱在56.279的9,所以数字适合在空间。我想我需要单独获取每个数字,除了9,并将它们插入一个字符数组...

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...

任何其他想法?

谢谢!

推荐答案

要拥有n的十进制数, (x modulo x * 10 ^(n-1))* 10)

To have the n decimal number of your double x you can do E((x modulo x*10^(n-1))*10)

这篇关于方式从双数据类型获取特定的整数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆