MidpointRounding
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user