private static void Truncate(ref Decimal d) { uint flags = d.uflags; if ((flags & ScaleMask) != 0) { DecCalc.InternalRound(ref d, (byte)(flags >> ScaleShift), DecCalc.RoundingMode.Truncate); } }
// Rounds a Decimal to an integer value. The Decimal argument is rounded // towards negative infinity. // public static Decimal Floor(Decimal d) { uint flags = d.uflags; if ((flags & ScaleMask) != 0) { DecCalc.InternalRound(ref d, (byte)(flags >> ScaleShift), DecCalc.RoundingMode.Floor); } return(d); }
private static Decimal Round(ref Decimal d, int decimals, MidpointRounding mode) { if ((uint)decimals > 28) { throw new ArgumentOutOfRangeException(nameof(decimals), SR.ArgumentOutOfRange_DecimalRound); } if ((uint)mode > (uint)MidpointRounding.AwayFromZero) { throw new ArgumentException(SR.Format(SR.Argument_InvalidEnumValue, mode, nameof(MidpointRounding)), nameof(mode)); } int scale = d.Scale - decimals; if (scale > 0) { DecCalc.InternalRound(ref d, (uint)scale, (DecCalc.RoundingMode)mode); } return(d); }