Beispiel #1
0
        public void FormatUsingDefaults()
        {
            NumberFormatter fmt = new NumberFormatter("en-US");

            Assert.AreEqual("1,234.00", fmt.Format(1234));
            Assert.AreEqual("1,234.56", fmt.Format(1234.56));
            Assert.AreEqual("-1,234.00", fmt.Format(-1234));
            Assert.AreEqual("-1,234.56", fmt.Format(-1234.56));

            fmt = new NumberFormatter("sr-SP-Latn");
            Assert.AreEqual("1.234,00", fmt.Format(1234));
            Assert.AreEqual("1.234,56", fmt.Format(1234.56));
            Assert.AreEqual("-1.234,00", fmt.Format(-1234));
            Assert.AreEqual("-1.234,56", fmt.Format(-1234.56));
        }
Beispiel #2
0
        public void FormatUsingCustomSettings()
        {
            NumberFormatter fmt = new NumberFormatter("en-US");

            fmt.DecimalDigits   = 0;
            fmt.NegativePattern = 0;
            Assert.AreEqual("1,234", fmt.Format(1234));
            Assert.AreEqual("1,235", fmt.Format(1234.56));
            Assert.AreEqual("(1,234)", fmt.Format(-1234));
            Assert.AreEqual("(1,235)", fmt.Format(-1234.56));

            fmt                = new NumberFormatter("sr-SP-Cyrl");
            fmt.GroupSizes     = new int[] { 1, 2 };
            fmt.GroupSeparator = "'";
            Assert.AreEqual("1'23'4,00", fmt.Format(1234));
            Assert.AreEqual("1'23'4,56", fmt.Format(1234.56));
            Assert.AreEqual("-1'23'4,00", fmt.Format(-1234));
            Assert.AreEqual("-1'23'4,56", fmt.Format(-1234.56));
        }
Beispiel #3
0
        public void FormatNonNumber()
        {
            NumberFormatter fmt = new NumberFormatter();

            Assert.Throws <ArgumentException>(() => fmt.Format("not a number"));
        }
Beispiel #4
0
        public void FormatNullValue()
        {
            NumberFormatter fmt = new NumberFormatter();

            Assert.Throws <ArgumentNullException>(() => fmt.Format(null));
        }