コード例 #1
0
 /// <summary>
 /// Implements the conversion from decimal dollars into their word representation.
 /// Uses the LiteralifyLib to do so.  An upperbound for the amount of dollars applies
 /// according to the library.
 /// </summary>
 /// <param name="dollars">Dollars and cents in decimal form.</param>
 /// <returns>Word representation.</returns>
 public string AsLiteral(decimal dollars)
 {
     try {
         string s = LiteralifyDollars.ToString(dollars);
         return(s);
     } catch (ArgumentOutOfRangeException e) {
         throw new FaultException(e.Message);
     }
 }
コード例 #2
0
        public void MillionsTest()
        {
            Dictionary <decimal, string> mill = new Dictionary <decimal, string>
            {
                { 834734634.43m, "eight hundred thirty-four million seven hundred thirty-four thousand six hundred thirty-four dollars and forty-three cents" },
                { 511412321.21m, "five hundred eleven million four hundred twelve thousand three hundred twenty-one dollars and twenty-one cents" },
                { 101202303.13m, "one hundred one million two hundred two thousand three hundred three dollars and thirteen cents" }
            };

            foreach (KeyValuePair <decimal, string> pair in mill)
            {
                Assert.AreEqual(
                    pair.Value,
                    LiteralifyDollars.ToString(pair.Key));
            }
        }
コード例 #3
0
        public void SmallNumbersTest()
        {
            Dictionary <decimal, string> small = new Dictionary <decimal, string>
            {
                { 0.42m, "zero dollars and forty-two cents" },
                { 1.37m, "one dollar and thirty-seven cents" },
                { 19.11m, "nineteen dollars and eleven cents" },
                { 17.66m, "seventeen dollars and sixty-six cents" }
            };

            foreach (KeyValuePair <decimal, string> pair in small)
            {
                Assert.AreEqual(
                    pair.Value,
                    LiteralifyDollars.ToString(pair.Key));
            }
        }
コード例 #4
0
        public void ExamplesTest()
        {
            Dictionary <decimal, string> examples = new Dictionary <decimal, string>
            {
                { 0.0m, "zero dollars" },
                { 1m, "one dollar" },
                { 25.1m, "twenty-five dollars and ten cents" },
                { 0.01m, "zero dollars and one cent" },
                { 45100m, "forty-five thousand one hundred dollars" },
                { 999999999.99m, "nine hundred ninety-nine million nine hundred ninety-nine thousand nine hundred ninety-nine dollars and ninety-nine cents" },
                { 99.9m, "ninety-nine dollars and ninety cents" },
                { 90m, "ninety dollars" }
            };

            foreach (KeyValuePair <decimal, string> pair in examples)
            {
                Assert.AreEqual(
                    pair.Value,
                    LiteralifyDollars.ToString(pair.Key));
            }
        }
コード例 #5
0
 public void LiteralifyToStringOverload()
 {
     Assert.AreEqual(LiteralifyDollars.ToString(42.9m), LiteralifyDollars.ToString(42, 90));
 }