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); }
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); }
public static decimal Floor(Decimal d) { return(Decimal.Floor(d)); }
// 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))); }