Intermediate

模運算計算器

計算 a ÷ b 的商與餘數,並提供截斷、向下取整和歐幾里得三種模運算慣例以處理負數。
Number being divided
Cannot be zero
Remainder (truncated)
2

Sign matches the dividend (JavaScript % operator)

Quotient (truncated)
3
Truncated remainder
2
Floored remainder
2
Euclidean remainder
2
00.61.31.92.53.13.84.45Euclidean remainder within [0, |b|)
Step by step
  1. 1

    Quotient (rounded toward zero)

    trunc(17 ÷ 5) = 3
  2. 2

    Truncated remainder

    17 − 5 × 3 = 2
    Sign follows the dividend — this matches the JavaScript % operator.
計算結果僅為一般資訊用途的估算值,並非專業建議——在仰賴重要結果之前,請務必自行獨立查證。 閱讀完整免責聲明.
快速解答

此計算機如何運作?

a ÷ b 的模運算是除法後的餘數。以 q = trunc(a/b) 為準,截斷餘數為 a − b·q(符號與 a 相同)。向下取整和歐幾里得變體改變商的取整方式,使餘數符合除數的符號或保持非負——這僅在 a 或 b 為負數時才有所不同。

公式
r = a − b × q,其中 q 取決於取整慣例(截斷 / 向下 / 歐幾里得)
How this is calculated

輸入被除數 a(被除的數)和除數 b(用於除的數)。除數不能為零,因為零除未定義,計算器在此情況下不回傳結果。

商為 q = trunc(a / b),向零取整。截斷餘數 rT = a − b·q 是大多數程式語言(以及 JavaScript 的 % 運算符)產生的結果:其符號與被除數 a 相同。向下取整餘數 rF = a − b·floor(a / b) 符號與除數 b 相同,這是 Python 的 % 和模數算術使用的慣例。歐幾里得餘數 rE = a − b·floor(a / |b|) 始終非負(0 ≤ rE < |b|),在數論中更為常用。

當 a 和 b 均為正數時,三種餘數相同。只有當 a 或 b 為負數時才有所不同。輸入可以是任何實數——允許小數值,相同的公式同樣適用,但模運算最常用於整數。

常見問題

它們對商使用不同的取整規則。截斷向零取整(C/JavaScript),向下取整向負無窮取整(Python),歐幾里得始終產生非負餘數。對於正數輸入,三者結果相同。

零除未定義,因此計算器顯示警告且不回傳結果。請選擇非零除數。

JavaScript、C、C++、Java 和 Go 使用截斷餘數(符號與被除數相同)。Python 和 Ruby 使用向下取整餘數(符號與除數相同)。

也稱為

取模計算
餘數計算
mod計算
求餘數
modulo
模運算
取餘數
餘數

APA

TG we-Calculate Editorial Team. (2026). 模運算計算器 [Online calculator]. TG we-Calculate. https://we-calculate.com/zh-tw/calculator/modulo-calculator

Chicago

TG we-Calculate Editorial Team. "模運算計算器." TG we-Calculate. 2026. https://we-calculate.com/zh-tw/calculator/modulo-calculator.

IEEE

TG we-Calculate Editorial Team, "模運算計算器," TG we-Calculate, 2026. [Online]. Available: https://we-calculate.com/zh-tw/calculator/modulo-calculator

BibTeX

@misc{wecalculate_modulo_calculator, title = {模運算計算器}, author = {{TG we-Calculate Editorial Team}}, howpublished = {\url{https://we-calculate.com/zh-tw/calculator/modulo-calculator}}, year = {2026}, note = {TG we-Calculate} }

這個計算機對您有幫助嗎?