[算術運算符]
說明
除法是四種主要算術運算之一。運算符/
(斜杠)對兩個操作數進行運算以產生結果。
用法
result = numerator / denominator;
參數
result
: 多變的。允許的數據類型:int
,float
,double
,byte
,short
,long
.
numerator
: 變量或常量。允許的數據類型:int
,float
,double
,byte
,short
,long
.
denominator
:非零變量或常數。允許的數據類型:int
,float
,double
,byte
,short
,long
.
示例代碼
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
注意事項和警告
-
如果其中一個數字(操作數)是 float 類型或 double 類型,則浮點數學將用於計算。
-
如果操作數是浮點/雙精度數據類型,並且存儲結果的變量是整數,則隻存儲整數部分,丟失數字的小數部分。
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
相關用法
- Arduino //用法及代碼示例
- Arduino /=用法及代碼示例
- Arduino /* */用法及代碼示例
- Arduino long用法及代碼示例
- Arduino Arduino_EMBRYO_2 - setLengthXY()用法及代碼示例
- Arduino ~用法及代碼示例
- Arduino ArduinoBLE - bleDevice.advertisedServiceUuidCount()用法及代碼示例
- Arduino const用法及代碼示例
- Arduino Ethernet - server.begin()用法及代碼示例
- Arduino ArduinoBLE - BLEService()用法及代碼示例
- Arduino digitalWrite()用法及代碼示例
- Arduino ArduinoBLE - bleCharacteristic.subscribe()用法及代碼示例
- Arduino Servo - attach()用法及代碼示例
- Arduino write()用法及代碼示例
- Arduino Arduino_LSM9DS1 - readGyroscope()用法及代碼示例
- Arduino ArduinoSound - FFTAnalyzer.input()用法及代碼示例
- Arduino MKRGSM - gprs.attachGPRS()用法及代碼示例
- Arduino WiFiNINA - WiFi.config()用法及代碼示例
- Arduino MKRGSM - sms.read()用法及代碼示例
- Arduino MKRNB - getCurrentCarrier()用法及代碼示例
- Arduino Scheduler - Scheduler.startLoop()用法及代碼示例
- Arduino Arduino_LSM9DS1 - magneticFieldAvailable()用法及代碼示例
- Arduino MKRWAN - available()用法及代碼示例
- Arduino ArduinoBLE - BLE.poll()用法及代碼示例
- Arduino ArduinoBLE - bleCharacteristic.hasDescriptor()用法及代碼示例
注:本文由純淨天空篩選整理自arduino.cc大神的英文原創作品 /。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。