public void ParseNullOrEmptyValue()
        {
            CurrencyFormatter fmt = new CurrencyFormatter();

            Assert.AreEqual(0, fmt.Parse(null));
            Assert.IsTrue(fmt.Parse("") is double);
        }
Esempio n. 2
0
        public void ParseUsingDefaults()
        {
            CurrencyFormatter fmt = new CurrencyFormatter("en-US");

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

            fmt = new CurrencyFormatter(CultureInfoUtils.SerbianLatinCultureName);
#if NET_4_0
            Assert.AreEqual(1234, fmt.Parse("1.234,00 din."));
            Assert.AreEqual(1234.56, fmt.Parse("1.234,56 din."));
            Assert.AreEqual(-1234, fmt.Parse("-1.234,00 din."));
            Assert.AreEqual(-1234.56, fmt.Parse("-1.234,56 din."));
#else
            Assert.AreEqual(1234, fmt.Parse("1.234,00 Din."));
            Assert.AreEqual(1234.56, fmt.Parse("1.234,56 Din."));
            Assert.AreEqual(-1234, fmt.Parse("-1.234,00 Din."));
            Assert.AreEqual(-1234.56, fmt.Parse("-1.234,56 Din."));
#endif

            fmt = new CurrencyFormatter(CultureInfoUtils.SerbianCyrillicCultureName);
#if NET_4_0
            Assert.AreEqual(1234, fmt.Parse("1.234,00 дин."));
            Assert.AreEqual(1234.56, fmt.Parse("1.234,56 дин."));
            Assert.AreEqual(-1234, fmt.Parse("-1.234,00 дин."));
            Assert.AreEqual(-1234.56, fmt.Parse("-1.234,56 дин."));
#else
            Assert.AreEqual(1234, fmt.Parse("1.234,00 Дин."));
            Assert.AreEqual(1234.56, fmt.Parse("1.234,56 Дин."));
            Assert.AreEqual(-1234, fmt.Parse("-1.234,00 Дин."));
            Assert.AreEqual(-1234.56, fmt.Parse("-1.234,56 Дин."));
#endif
        }
        public void ParseUsingCustomSettings()
        {
            CurrencyFormatter fmt = new CurrencyFormatter("en-US");

            fmt.DecimalDigits   = 0;
            fmt.NegativePattern = 1;
            Assert.AreEqual(1234, fmt.Parse("$1,234"));
            Assert.AreEqual(1234.56, fmt.Parse("$1,234.56"));
            Assert.AreEqual(-1234, fmt.Parse("-$1,234"));
            Assert.AreEqual(-1234.56, fmt.Parse("-$1,234.56"));

            fmt = new CurrencyFormatter("sr-SP-Latn");
            fmt.PositivePattern = 1;
            fmt.CurrencySymbol  = "din";
            Assert.AreEqual(1234, fmt.Parse("1.234,00din"));
            Assert.AreEqual(1234.56, fmt.Parse("1.234,56din"));
            Assert.AreEqual(-1234, fmt.Parse("-1.234,00 din"));
            Assert.AreEqual(-1234.56, fmt.Parse("-1.234,56 din"));

            fmt                = new CurrencyFormatter(CultureInfoUtils.SerbianCyrillicCultureName);
            fmt.GroupSizes     = new int[] { 1, 2 };
            fmt.GroupSeparator = "'";
            Assert.AreEqual(1234, fmt.Parse("1'23'4,00 Дин."));
            Assert.AreEqual(1234.56, fmt.Parse("1'23'4,56 Дин."));
            Assert.AreEqual(-1234, fmt.Parse("-1'23'4,00 Дин."));
            Assert.AreEqual(-1234.56, fmt.Parse("-1'23'4,56 Дин."));
        }
Esempio n. 4
0
        public void ParseUsingDefaults()
        {
            CurrencyFormatter fmt = new CurrencyFormatter("en-US");

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

            fmt = new CurrencyFormatter(CultureInfoUtils.SerbianLatinCultureName);

            if (CultureInfoUtils.OperatingSystemIsAfterWindows7AndBeforeWindows10Build10586 && CultureInfoUtils.ClrIsVersion4OrLater)
            {
                Assert.AreEqual(1234, fmt.Parse("1.234,00 din."));
                Assert.AreEqual(1234.56, fmt.Parse("1.234,56 din."));
                Assert.AreEqual(-1234, fmt.Parse("-1.234,00 din."));
                Assert.AreEqual(-1234.56, fmt.Parse("-1.234,56 din."));
            }

            else if (CultureInfoUtils.OperatingSystemIsAtLeastWindows10Build10586 && CultureInfoUtils.ClrIsVersion4OrLater)
            {
                Assert.AreEqual(1234, fmt.Parse("1.234 RSD"));
                Assert.AreEqual(-1234, fmt.Parse("-1.234 RSD"));
            }

            else
            {
                Assert.AreEqual(1234, fmt.Parse("1.234,00 Din."));
                Assert.AreEqual(1234.56, fmt.Parse("1.234,56 Din."));
                Assert.AreEqual(-1234, fmt.Parse("-1.234,00 Din."));
                Assert.AreEqual(-1234.56, fmt.Parse("-1.234,56 Din."));
            }

            fmt = new CurrencyFormatter(CultureInfoUtils.SerbianCyrillicCultureName);

            if (CultureInfoUtils.OperatingSystemIsAfterWindows7 && CultureInfoUtils.ClrIsVersion4OrLater)
            {
                Assert.AreEqual(1234, fmt.Parse("1.234,00 дин."));
                Assert.AreEqual(1234.56, fmt.Parse("1.234,56 дин."));
                Assert.AreEqual(-1234, fmt.Parse("-1.234,00 дин."));
                Assert.AreEqual(-1234.56, fmt.Parse("-1.234,56 дин."));
            }
            else
            {
                Assert.AreEqual(1234, fmt.Parse("1.234,00 Дин."));
                Assert.AreEqual(1234.56, fmt.Parse("1.234,56 Дин."));
                Assert.AreEqual(-1234, fmt.Parse("-1.234,00 Дин."));
                Assert.AreEqual(-1234.56, fmt.Parse("-1.234,56 Дин."));
            }
        }
 public void ParseNullOrEmptyValue()
 {
     CurrencyFormatter fmt = new CurrencyFormatter();
     Assert.AreEqual(0, fmt.Parse(null));
     Assert.IsTrue(fmt.Parse("") is double);
 }
        public void ParseUsingCustomSettings()
        {
            CurrencyFormatter fmt = new CurrencyFormatter("en-US");
            fmt.DecimalDigits = 0;
            fmt.NegativePattern = 1;
            Assert.AreEqual(1234, fmt.Parse("$1,234"));
            Assert.AreEqual(1234.56, fmt.Parse("$1,234.56"));
            Assert.AreEqual(-1234, fmt.Parse("-$1,234"));
            Assert.AreEqual(-1234.56, fmt.Parse("-$1,234.56"));

            fmt = new CurrencyFormatter("sr-SP-Latn");
            fmt.PositivePattern = 1;
            fmt.CurrencySymbol = "din";
            Assert.AreEqual(1234, fmt.Parse("1.234,00din"));
            Assert.AreEqual(1234.56, fmt.Parse("1.234,56din"));
            Assert.AreEqual(-1234, fmt.Parse("-1.234,00 din"));
            Assert.AreEqual(-1234.56, fmt.Parse("-1.234,56 din"));

            fmt = new CurrencyFormatter(CultureInfoUtils.SerbianCyrillicCultureName);
            fmt.GroupSizes = new int[] { 1, 2 };
            fmt.GroupSeparator = "'";

            if (CultureInfoUtils.OperatingSystemIsAfterWindows7 && CultureInfoUtils.ClrIsVersion4OrLater)
            {
                Assert.AreEqual(1234, fmt.Parse("1'23'4,00 дин."));
                Assert.AreEqual(1234.56, fmt.Parse("1'23'4,56 дин."));
                Assert.AreEqual(-1234, fmt.Parse("-1'23'4,00 дин."));
                Assert.AreEqual(-1234.56, fmt.Parse("-1'23'4,56 дин."));
            }
            else
            {
                Assert.AreEqual(1234, fmt.Parse("1'23'4,00 Дин."));
                Assert.AreEqual(1234.56, fmt.Parse("1'23'4,56 Дин."));
                Assert.AreEqual(-1234, fmt.Parse("-1'23'4,00 Дин."));
                Assert.AreEqual(-1234.56, fmt.Parse("-1'23'4,56 Дин."));
            }

        }
        public void ParseUsingDefaults()
        {
            CurrencyFormatter fmt = new CurrencyFormatter("en-US");
            Assert.AreEqual(1234, fmt.Parse("$1,234.00"));
            Assert.AreEqual(1234.56, fmt.Parse("$1,234.56"));
            Assert.AreEqual(-1234, fmt.Parse("($1,234.00)"));
            Assert.AreEqual(-1234.56, fmt.Parse("($1,234.56)"));

            fmt = new CurrencyFormatter(CultureInfoUtils.SerbianLatinCultureName);

            if (CultureInfoUtils.OperatingSystemIsAfterWindows7AndBeforeWindows10Build10586 && CultureInfoUtils.ClrIsVersion4OrLater)
            {
                Assert.AreEqual(1234, fmt.Parse("1.234,00 din."));
                Assert.AreEqual(1234.56, fmt.Parse("1.234,56 din."));
                Assert.AreEqual(-1234, fmt.Parse("-1.234,00 din."));
                Assert.AreEqual(-1234.56, fmt.Parse("-1.234,56 din."));
            }

            else if (CultureInfoUtils.OperatingSystemIsAtLeastWindows10Build10586 && CultureInfoUtils.ClrIsVersion4OrLater)
            {
                Assert.AreEqual(1234, fmt.Parse("1.234 RSD"));
                Assert.AreEqual(-1234, fmt.Parse("-1.234 RSD"));
            }

            else
            {
                Assert.AreEqual(1234, fmt.Parse("1.234,00 Din."));
                Assert.AreEqual(1234.56, fmt.Parse("1.234,56 Din."));
                Assert.AreEqual(-1234, fmt.Parse("-1.234,00 Din."));
                Assert.AreEqual(-1234.56, fmt.Parse("-1.234,56 Din."));
            }

            fmt = new CurrencyFormatter(CultureInfoUtils.SerbianCyrillicCultureName);

            if (CultureInfoUtils.OperatingSystemIsAfterWindows7 && CultureInfoUtils.ClrIsVersion4OrLater)
            {
                Assert.AreEqual(1234, fmt.Parse("1.234,00 дин."));
                Assert.AreEqual(1234.56, fmt.Parse("1.234,56 дин."));
                Assert.AreEqual(-1234, fmt.Parse("-1.234,00 дин."));
                Assert.AreEqual(-1234.56, fmt.Parse("-1.234,56 дин."));
            }
            else
            {
                Assert.AreEqual(1234, fmt.Parse("1.234,00 Дин."));
                Assert.AreEqual(1234.56, fmt.Parse("1.234,56 Дин."));
                Assert.AreEqual(-1234, fmt.Parse("-1.234,00 Дин."));
                Assert.AreEqual(-1234.56, fmt.Parse("-1.234,56 Дин."));
            }

        }
Esempio n. 8
0
        public void ParseUsingDefaults()
        {
            CurrencyFormatter fmt = new CurrencyFormatter("en-US");
            Assert.AreEqual(1234, fmt.Parse("$1,234.00"));
            Assert.AreEqual(1234.56, fmt.Parse("$1,234.56"));
            Assert.AreEqual(-1234, fmt.Parse("($1,234.00)"));
            Assert.AreEqual(-1234.56, fmt.Parse("($1,234.56)"));

            fmt = new CurrencyFormatter(CultureInfoUtils.SerbianLatinCultureName);
            Assert.AreEqual(1234, fmt.Parse("1.234,00 Din."));
            Assert.AreEqual(1234.56, fmt.Parse("1.234,56 Din."));
            Assert.AreEqual(-1234, fmt.Parse("-1.234,00 Din."));
            Assert.AreEqual(-1234.56, fmt.Parse("-1.234,56 Din."));

            fmt = new CurrencyFormatter(CultureInfoUtils.SerbianCyrillicCultureName);
            Assert.AreEqual(1234, fmt.Parse("1.234,00 Дин."));
            Assert.AreEqual(1234.56, fmt.Parse("1.234,56 Дин."));
            Assert.AreEqual(-1234, fmt.Parse("-1.234,00 Дин."));
            Assert.AreEqual(-1234.56, fmt.Parse("-1.234,56 Дин."));
        }