Skip to content

Latest commit

 

History

History
29 lines (26 loc) · 871 Bytes

QW0013.md

File metadata and controls

29 lines (26 loc) · 871 Bytes

QW0013: Use Qowaiv decimal rounding

Qowaiv decimal rounding has three core benefits:

  1. Via an extension-method, the code is easier to follow.
  2. It supports a lot more rounding methods.
  3. It allows negative values for the amount of decimals (equivalent to multiple of ten, hundred, etc.).

Non-compliant

public void Method(decimal value)
{
    decimal floor = Math.Floor(value)
    decimal ceiling = Math.Ceiling(value)
    decimal truncate = Math.Truncate(value)
    decimal rounded = Math.Round(value, 3, MidpointRouding.ToEven);
}

Compliant

public void Method(decimal value)
{
    decimal floor = value.Round(0, DecimalRounding.Floor);
    decimal ceiling = value.Round(0, DecimalRounding.Ceiling);
    decimal truncate = value.Round(0, DecimalRounding.Truncate);
    decimal rounded = value.Round(3, DecimalRounding.ToEven);
}