Created
May 3, 2012 10:03
-
-
Save johnnonolan/2584831 to your computer and use it in GitHub Desktop.
I hate the rounding in .NET
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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