Пример #1
0
        public static decimal Round(decimal d)
        {
            // Just call Decimal.Round(d, 0); when it rounds well.
            decimal int_part = Decimal.Floor(d);
            decimal dec_part = d - int_part;

            if (((dec_part == 0.5M) &&
                 ((2.0M * ((int_part / 2.0M) -
                           Decimal.Floor(int_part / 2.0M))) != 0.0M)) ||
                (dec_part > 0.5M))
            {
                int_part++;
            }
            return(int_part);
        }
Пример #2
0
        static decimal RoundAwayFromZero(decimal d)
        {
            decimal int_part = Decimal.Floor(d);
            decimal dec_part = d - int_part;

            if (int_part >= 0 && dec_part >= 0.5M)
            {
                int_part++;
            }
            else if (int_part < 0 && dec_part > 0.5M)
            {
                int_part++;
            }
            return(int_part);
        }
Пример #3
0
 public static decimal Floor(Decimal d)
 {
     return(Decimal.Floor(d));
 }
Пример #4
0
 // Rounds a Decimal to an integer value. The Decimal argument is rounded
 // towards positive infinity.
 public static Decimal Ceiling(Decimal d)
 {
     return(-(Decimal.Floor(-d)));
 }