2
2

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.

.NETで割り算の結果を整数にしたいとき

Last updated at Posted at 2017-04-03

C#でおもむろに
int a = 3/2;
なんてやるとaの結果は1になります。
つまりは切り捨てです。

切り上げや四捨五入をしたいときはこう?なんかめんどくさい・・・
int a = Convert.ToInt32(Math.Ceiling((double)3/2));

Math関数

  • Floor :切り捨て
  • Ceiling:切り上げ
  • Round :銀行丸め(パラメータにより四捨五入)
2
2
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
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?