Skip to content

Instantly share code, notes, and snippets.

@johnnonolan
Created May 3, 2012 10:03
Show Gist options
  • Select an option

  • Save johnnonolan/2584831 to your computer and use it in GitHub Desktop.

Select an option

Save johnnonolan/2584831 to your computer and use it in GitHub Desktop.
I hate the rounding in .NET
namespace Rounding
{
[TestFixture]
public class Class1
{
//BRAIN HURTS
[Test]
public void Default()
{
Assert.That(Decimal.Round(1.5m),Is.EqualTo(2));
Assert.That(Decimal.Round(0.5m), Is.EqualTo(0));
Assert.That(Decimal.Round(1.495m, 2), Is.EqualTo(1.5m));
}
[Test]
public void AwayFromZero()
{
Assert.That(Decimal.Round(1.5m, MidpointRounding.AwayFromZero), Is.EqualTo(2));
Assert.That(Decimal.Round(0.5m ,MidpointRounding.AwayFromZero), Is.EqualTo(1));
Assert.That(Decimal.Round(1.495m,2,MidpointRounding.AwayFromZero), Is.EqualTo(1.5m));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment