Example #1
0
        public override string ToWord()
        {
            var sb = new StringBuilder();

            if (number < 10)
            {
                var one = new OnePlace(number);
                var word = one.ToWord();
                sb.Append(word == "One"
                              ? String.Format("{0} Cent", one.ToWord())
                              : String.Format("{0} Cents", one.ToWord()));
            }
            else
            {
                var ten = new TenPlace(number);
                sb.Append(String.Format("{0} Cents", ten.ToWord()));
            }

            return sb.ToString();
        }
Example #2
0
 public void ShouldGetTenObject()
 {
     var ten = new TenPlace(12);
     Assert.AreEqual(ten.ToWord(), "Twelve");
 }
Example #3
0
 public void ShouldNotGetTenObject()
 {
     Assert.Throws<InvalidNumberRangeException>(delegate { var ten = new TenPlace(120); });
 }
Example #4
0
 public void ShouldGetTenWord91()
 {
     var ten = new TenPlace(92);
     var word = ten.ToWord();
     Assert.AreEqual(word, "Ninety Two");
 }
Example #5
0
 public void ShouldGetTenWord80()
 {
     var ten = new TenPlace(80);
     var word = ten.ToWord();
     Assert.AreEqual(word, "Eighty");
 }
Example #6
0
 public void ShouldGetTenWord36()
 {
     var ten = new TenPlace(36);
     var word = ten.ToWord();
     Assert.AreEqual(word, "Thirty Six");
 }
Example #7
0
        private void Init(decimal number)
        {
            //maximum number 999 million.
            if (number < 0 || number > 999999999)
                throw new InvalidNumberRangeException();

            var n = (int)number;
            if (Validator.ValidateMillionPlace(n))
                million = new MillionPlace(n);

            var n1 = (n >= 1000000) ? n - (n / 1000000 * 1000000) : n;
            if (Validator.ValidateThousandPlace(n1))
                thousand = new ThousandPlace((int)n1);

            var n2 = (n1 >= 1000) ? n - (n / 1000 * 1000) : n1;
            if (Validator.ValidateHundredPlace(n2))
                hundred = new HundredPlace((int)n2);

            var n3 = (n2 >= 100) ? n - (n / 100 * 100) : n2;
            if (Validator.ValidateTenPlace(n3))
                ten = new TenPlace((int)n3);
            else
            {
                var n4 = (n3 >= 10) ? n - (n / 10 * 10) : n3;
                if (Validator.ValidateOnePlace(n4))
                    one = new OnePlace((int)n4);
            }

            var centStr = "";
            var centArray = number.ToString("0.00").Split(".".ToCharArray());
            if (centArray.Length == 2)
                centStr = centArray[1];
            var c = 0;
            if (int.TryParse(centStr, out c) && Validator.ValidateCentPlace(c))
            {
                cent = new CentPlace(c);
            }
        }