我有一个双重:
double d = 25.342;
如何将其转换为25
价值?
如果是-12.46
我想得到-13
。
int i = (int)floor(25.342);
int i = (int)floor(25.342);
请注意,这会将 12.99999 转换为 12。
参考:
其中 x 是您的 25.342
整数 i = x >= 0 ?(int)(x+0.5) : (int)(x-0.5)
#include <math.h>
#include <stdio.h>
int main(){
double d = 25.342;
double e = -12.99;
printf("%d\n",(int)round(d)); // 25
printf("%d\n",(int)round(e)); // -13
return 0;
}
您可能还想看看 stdint.h