Ejemplo n.º 1
0
        /// <summary>
        /// Scales a tolerance to match the precision of the expected value.
        /// </summary>
        public static decimal GetScaledTolerance(decimal expected, int tolerance, bool countTrailingZeros)
        {
            decimal toleranceAtScale = tolerance;
            var     precision        = DecimalEx.GetDecimalPlaces(expected, countTrailingZeros);

            for (var i = 0; i < precision; i++)
            {
                toleranceAtScale /= 10m;
            }
            return(toleranceAtScale);
        }
Ejemplo n.º 2
0
        public void CountTrailingZeros()
        {
            var x = DecimalEx.SmallestNonZeroDec;

            for (int i = 28; i >= 0; i--)
            {
                Assert.That(DecimalEx.GetDecimalPlaces(x, false), Is.EqualTo(i));
                x *= 10;
            }

            x = -DecimalEx.SmallestNonZeroDec;
            for (int i = 28; i >= 0; i--)
            {
                Assert.That(DecimalEx.GetDecimalPlaces(x, false), Is.EqualTo(i));
                x *= 10;
            }
        }
Ejemplo n.º 3
0
 public int ExcludeTrailingZeros(decimal dec)
 {
     return(DecimalEx.GetDecimalPlaces(dec, false));
 }