/

名称

/

説明

除算は四則演算の一つである。演算子/(スラッシュ)は、二つのオペランドの商を計算する。

書式

result = numerator / denominator;

引数

result変数。利用できるデータ型: int, float, double, byte, short, long。
numerator変数か定数。利用できるデータ型: int, float, double, byte, short, long。
denominator変数か定数。利用できるデータ型: int, float, double, byte, short, long。

使用例

1
2
3
4
int a = 50;
int b = 10;
int c = 0;
c = a / b;  // the variable 'c' gets a value of 5 after this statement is executed

注意

  1. オペランドの一つがfloatかdoubleの場合は、浮動小数点計算が使われる。
  2. オペランドがfloatかdoubleで、除算の結果を格納する変数が整数型の場合、結果の整数部分だけが格納され、小数点以下は捨てられる。
1
2
3
4
float a = 55.5;
float b = 6.6;
int c = 0;
c = a / b;  // the variable 'c' stores a value of 8 only as opposed to the expected result of 8.409

参照

オリジナルのページ

https://www.arduino.cc/reference/en/language/structure/arithmetic-operators/division/

Last Revision: 2019/06/11

最終更新日

January 4, 2024

inserted by FC2 system