4
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

C言語で小数点以下を切り捨てて整数部分だけ取り出す

Posted at

ググるとmodf関数を使う方法とか、floor関数を使う方法とかはでてきたけど、自分で試したみた結果これで十分じゃね?って思ったのでメモしておきます。

aaa.c
double a = 3.32984;
int b = a;

これでb=3が代入されて、aの整数部分だけ取り出せます。

4
7
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?