diff --git a/Content.Shared/Chemistry/ReagentUnit.cs b/Content.Shared/Chemistry/ReagentUnit.cs index 63385fe297..43c2354f03 100644 --- a/Content.Shared/Chemistry/ReagentUnit.cs +++ b/Content.Shared/Chemistry/ReagentUnit.cs @@ -32,7 +32,7 @@ namespace Content.Shared.Chemistry public static ReagentUnit New(decimal value) { - return new ReagentUnit((int) Math.Round(value * (decimal) Math.Pow(10, Shift))); + return new ReagentUnit((int) Math.Round(value * (decimal) Math.Pow(10, Shift), MidpointRounding.AwayFromZero)); } public static ReagentUnit New(float value) @@ -42,12 +42,12 @@ namespace Content.Shared.Chemistry private static int FromFloat(float value) { - return (int) Math.Round(value * (float) Math.Pow(10, Shift)); + return (int) Math.Round(value * (float) Math.Pow(10, Shift), MidpointRounding.AwayFromZero); } public static ReagentUnit New(double value) { - return new ReagentUnit((int) Math.Round(value * Math.Pow(10, Shift))); + return new ReagentUnit((int) Math.Round(value * Math.Pow(10, Shift), MidpointRounding.AwayFromZero)); } public static ReagentUnit New(string value) diff --git a/Content.Tests/Shared/Chemistry/ReagentUnit_Tests.cs b/Content.Tests/Shared/Chemistry/ReagentUnit_Tests.cs index 46d391459b..003ecf4663 100644 --- a/Content.Tests/Shared/Chemistry/ReagentUnit_Tests.cs +++ b/Content.Tests/Shared/Chemistry/ReagentUnit_Tests.cs @@ -46,7 +46,7 @@ namespace Content.Tests.Shared.Chemistry } [Test] - [TestCase("1.005", "1")] + [TestCase("1.005", "1.01")] [TestCase("0.999", "1")] public void ReagentUnitStringTests(string value, string expected) { @@ -57,6 +57,7 @@ namespace Content.Tests.Shared.Chemistry [Test] [TestCase(1.001f, 1.001f, "2")] [TestCase(1.001f, 1.004f, "2")] + [TestCase(1f, 1.005f, "2.01")] [TestCase(1f, 2.005f, "3.01")] public void CalculusPlus(float aFloat, float bFloat, string expected) { @@ -111,11 +112,11 @@ namespace Content.Tests.Shared.Chemistry [Test] [TestCase(0.995f, 100)] - [TestCase(1.005f, 100)] + [TestCase(1.005f, 101)] [TestCase(2.005f, 201)] public void FloatRoundingTest(float a, int expected) { - var result = (int) Math.Round(a * (float) Math.Pow(10, 2)); + var result = (int) Math.Round(a * (float) Math.Pow(10, 2), MidpointRounding.AwayFromZero); Assert.AreEqual(expected, result); }