コード例 #1
0
ファイル: Helper.cs プロジェクト: urbrioche/DecimalMath
        /// <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);
        }
コード例 #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;
            }
        }
コード例 #3
0
 public int ExcludeTrailingZeros(decimal dec)
 {
     return(DecimalEx.GetDecimalPlaces(dec, false));
 }