dotnet / dotnet/csharpstandard

9.2.8 and 12.9.3 Unclear behavior of the operator % for decimals

Open
#81 1 comment 0 reactions 0 assignees View on GitHub
type: clarity
Dominant language
C#
Stars
815
Forks
99
Avg merge
1d 14h
Merged PRs (30d)
16

Description

> 10.2.8 The decimal type
> The result of an operation on values of type decimal is that which would result from calculating an exact result (preserving scale, as defined for each operator) and then rounding to fit the representation.

---

> 13.9.3 Division operator
> The result of x % y is the value produced by x – (x / y) \* y

The question is about evaluation of % operator. Does it evaluate as x – (x / y) \* y using exact arithmetics (no rounding) at all intermediate steps, and then rounds the result once? Or rounding happens during each intermediate step?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.