3.将double数据除去小数部分
作者:互联网
double double_int(double a)
{//去除double型数据的小数部分,保留整数部分
double i = 1, power = 1, a1 = 0;//i为a的整数位数,power为整数部分最高位权重
for (double n = a / 10; n >= 1; i++)//求i(整数位数)
n /= 10;
if (i < 10) return int(a);
else
{
for (int j = 1; j < i; j++)//求power
power *= 10;
for (int j = 0; j < i; power /= 10, j++)//求a的整数部分
a1 += int((a - a1) / power) * power;
return a1;
}
}
标签:10,power,int,double,整数,a1,除去,小数 来源: https://blog.csdn.net/qq_40925617/article/details/121667067