LoginSignup
3
1

More than 3 years have passed since last update.

VB.netプログラマがC#で割り算を行うときに気をつけること。

Last updated at Posted at 2019-05-16

C#で「商」を求めるには「/」を使いますが、その際に割られる数と割る数をともに整数型にしておく必要があります。逆に、小数が必要な場合には小数型に変換してから割り算を行わなければなりません。

<<商を求める>>

test.vb
  Dim num as Integer = 0
  num = 50 \ 3   '16が返る
test.cs
  Int num = 0;
  num = 50 / 3   //16が返る

<<小数を求める>>

test.vb
  Dim num as Single = 0
  num = 50 / 3   '16.666...が返る
test.cs
  Single num = 0; 
  num = 50.0 / 3.0;   //16.6666...が返る
3
1
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
3
1