當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Dart num.operator_modulo用法及代碼示例

dart:core 庫中num.operator_modulo 方法的用法介紹如下。

用法:

num operator %(
   num other   
)

這個數字的歐幾裏得模數 other

返回歐幾裏得除法的餘數。兩個整數 ab 的歐幾裏得除法產生兩個整數 qr 使得 a == b * q + r0 <= r < b.abs()

歐幾裏得除法隻為整數定義,但可以很容易地擴展到使用雙精度數。在這種情況下,q 仍然是整數,但 r 可能具有仍滿足 0 <= r < |b| 的非整數值。

返回值r 的符號始終為正。

有關截斷除法的其餘部分,請參見remainder

結果是 int ,如 int.% 所述,如果此數字和 other 都是整數,否則結果是 double

例子:

print(5 % 3); // 2
print(-5 % 3); // 1
print(5 % -3); // 2
print(-5 % -3); // 1

相關用法


注:本文由純淨天空篩選整理自dart.dev大神的英文原創作品 operator % method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。