using static System.Console;
using static System.Math;
using System.Diagnostics;
public static void Main() {
var tempo = new Stopwatch();
for (var valor = -10000M; valor <= 10000M; valor += 0.05M) valor.RoundMidPoint();
WriteLine("Arredondando em ms: {0}", tempo.ElapsedMilliseconds);
for (var valor = -10000.0; valor <= 10000.0; valor += 0.05) valor.RoundMidPoint();
WriteLine("Arredondando em ms: {0}", tempo.ElapsedMilliseconds);
WriteLine("Decimal Alternativo");
for (var valor = -10000M; valor <= 10000M; valor += 0.05M) valor.RoundMidPointAlt();
WriteLine("Arredondando em ms: {0}", tempo.ElapsedMilliseconds);
WriteLine("Double Alternativo");
for (var valor = -10000.0; valor <= 10000.0; valor += 0.05) valor.RoundMidPointAlt();
WriteLine("Arredondando em ms: {0}", tempo.ElapsedMilliseconds);
public static class RoundUtil {
public static Decimal RoundMidPoint(this Decimal value) => Sign(value) * Ceiling(Abs(value) * 2) / 2;
public static double RoundMidPoint(this double value) => Sign(value) * Ceiling(Abs(value) * 2) / 2;
public static Decimal RoundMidPointAlt(this Decimal value) {
int intPart = (int)value;
decimal decimalPart = value - intPart;
if (0 < decimalPart && decimalPart <= 0.5M) return intPart + 0.5M;
else if (0.5M < decimalPart) return intPart + 1;
public static double RoundMidPointAlt(this double value) {
int intPart = (int)value;
double decimalPart = value - intPart;
if (0 < decimalPart && decimalPart <= 0.5) return intPart + 0.5;
else if (0.5 < decimalPart) return intPart + 1;