Skip to content

Commit

Permalink
Fixed conversion to int in the Percentage struct.
Browse files Browse the repository at this point in the history
  • Loading branch information
Dirk Lemstra committed Jun 18, 2017
1 parent a42633f commit a17ca03
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Source/Magick.NET/Shared/Types/Percentage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ public double ToDouble()
/// <returns>An integer that represents the current percentage.</returns>
public int ToInt32()
{
return (int)_Value;
return (int)Math.Round(_Value, MidpointRounding.AwayFromZero);
}

/// <summary>
Expand Down
14 changes: 14 additions & 0 deletions Tests/Magick.NET.Tests/Shared/Types/PercentageTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,5 +97,19 @@ public void Test_Multiplication()
percentage = new Percentage(25);
Assert.AreEqual(2.5, 10.0 * percentage);
}

[TestMethod]
public void ToInt32_ZeroPointFour_ReturnsZero()
{
Percentage percentage = new Percentage(0.4);
Assert.AreEqual(0, percentage.ToInt32());
}

[TestMethod]
public void ToInt32_ZeroPointFive_ReturnsOne()
{
Percentage percentage = new Percentage(0.5);
Assert.AreEqual(1, percentage.ToInt32());
}
}
}

0 comments on commit a17ca03

Please sign in to comment.