我有一个
double
:
double d = 25.342;
如何将其转换为
25
?
如果是
-12.46
我想得到-13
.
int i = (int)floor(25.342);
你的
x
在哪里25.342
:
int 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