Index: Core/Common/src/Core.Common.Base/Data/RoundedDouble.cs =================================================================== diff -u -r9f494a06e4dd1e8b3bc6a7abbf193e11c4ba2c93 -r71e85bc10cc3a4ad8e5b37e5220e9ce11d3021e2 --- Core/Common/src/Core.Common.Base/Data/RoundedDouble.cs (.../RoundedDouble.cs) (revision 9f494a06e4dd1e8b3bc6a7abbf193e11c4ba2c93) +++ Core/Common/src/Core.Common.Base/Data/RoundedDouble.cs (.../RoundedDouble.cs) (revision 71e85bc10cc3a4ad8e5b37e5220e9ce11d3021e2) @@ -181,6 +181,44 @@ return Value.GetHashCode(); } + private static double RoundDouble(double value, int numberOfDecimalPlaces) + { + return IsSpecialDoubleValue(value) ? value : Math.Round(value, numberOfDecimalPlaces, MidpointRounding.AwayFromZero); + } + + /// + /// Validates . + /// + /// The new value for . + /// + /// Thrown when is not in range [0, 15]. + /// + private static void ValidateNumberOfDecimalPlaces(int numberOfDecimalPlaces) + { + if (numberOfDecimalPlaces < 0 || numberOfDecimalPlaces > MaximumNumberOfDecimalPlaces) + { + string message = string.Format(CultureInfo.CurrentCulture, + "Value must be in range [0, {0}].", + MaximumNumberOfDecimalPlaces); + throw new ArgumentOutOfRangeException(nameof(numberOfDecimalPlaces), + message); + } + } + + private static bool IsSpecialDoubleValue(double value) + { + return double.IsNaN(value) || + double.IsPositiveInfinity(value) || + double.IsNegativeInfinity(value); + } + + private string GetFormat() + { + return "F" + NumberOfDecimalPlaces; + } + + #region ToString + public override string ToString() { return ToString(null, null); @@ -201,6 +239,10 @@ return Value.ToString(format ?? GetFormat(), formatProvider ?? CultureInfo.CurrentCulture); } + #endregion + + #region CompareTo + public int CompareTo(object obj) { if (obj == null) @@ -231,6 +273,10 @@ return Value.CompareTo(other.Value); } + #endregion + + #region Equals + public bool Equals(double other) { return Value.Equals(other); @@ -253,43 +299,9 @@ return false; } - return Equals((RoundedDouble)obj); + return Equals((RoundedDouble) obj); } - private static double RoundDouble(double value, int numberOfDecimalPlaces) - { - return IsSpecialDoubleValue(value) ? value : Math.Round(value, numberOfDecimalPlaces, MidpointRounding.AwayFromZero); - } - - /// - /// Validates . - /// - /// The new value for . - /// - /// Thrown when is not in range [0, 15]. - /// - private static void ValidateNumberOfDecimalPlaces(int numberOfDecimalPlaces) - { - if (numberOfDecimalPlaces < 0 || numberOfDecimalPlaces > MaximumNumberOfDecimalPlaces) - { - string message = string.Format(CultureInfo.CurrentCulture, - "Value must be in range [0, {0}].", - MaximumNumberOfDecimalPlaces); - throw new ArgumentOutOfRangeException(nameof(numberOfDecimalPlaces), - message); - } - } - - private static bool IsSpecialDoubleValue(double value) - { - return double.IsNaN(value) || - double.IsPositiveInfinity(value) || - double.IsNegativeInfinity(value); - } - - private string GetFormat() - { - return "F" + NumberOfDecimalPlaces; - } + #endregion } } \ No newline at end of file