문제

두 배가 있습니다.

double d = 25.342;

어떻게 변환 할 수 있습니까? 25 값?

만약 그렇다면 -12.46 나는 가고 싶다 -13.

도움이 되었습니까?

해결책

int i = (int)floor(25.342);

다른 팁

int i = (int)floor(25.342);

이것은 12.99999로 변환됩니다.

ref :

http://www.codecogs.com/reference/c/math.h/floor.php

여기서 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를보고 싶을 수도 있습니다.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top