質問

ダブルがあります:

double d = 25.342;

どのようにして 25 値に変換できますか?

-12.46 の場合、 -13 を取得したい。

役に立ちましたか?

解決

int i = (int)floor(25.342);

他のヒント

int i = (int)floor(25.342);

これは12.99999を12に変換することに注意してください。

参照:

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