An integer division is rounded with Math.Ceiling, Floor, Round or Truncate, after its fraction is already gone
What it finds
Math.Ceiling(a / b) with two integers divides first, in integers, and drops the fraction; the rounding then has nothing left to round, so Math.Ceiling(7 / 2) is 3, not 4. Converting an operand to double or decimal first, or rounding with integer arithmetic, gives the intended value. The rule reports a call whose argument is a division of two operands declared as integers or written as integer literals, not both literals.
From the rule's source, rounded_integer_division.rs.
using System; class Pages{ int Count(int items, int size) => (int)Math.Ceiling(items / size);tx0 reports: items / size divides integers, so Math.Ceiling has no fraction left to round int Fine(int items, int size) => (int)Math.Ceiling(items / (double)size); double Half(long total) => Math.Round(total / 2);tx0 reports: total / 2 divides integers, so Math.Round has no fraction left to round} Turn it on, off or suppress it
The rule runs in every tier. To turn it off for a project, set its level in tx0.toml:
[rules]
"tx0/csharp:rounded-integer-division" = "off"To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:
// tx0: ignore[tx0/csharp:rounded-integer-division] reason="..."tx0 explain tx0/csharp:rounded-integer-division shows the same in the terminal. Found a false positive? Report it.