private void LoadNumbers()
        {
            DecimalFormatter formatter = new DecimalFormatter();

            formatter.IsGrouped = true;
            formatter.IsDecimalPointAlwaysDisplayed = true;
            DecimalFormatterTextblock.Text          = formatter.Format(12345.00);

            // Determine the current user's default currency.
            string currency = GlobalizationPreferences.Currencies[0];

            // Create currency formatter with current preferences
            CurrencyFormatter defaultCurrencyFormatter = new CurrencyFormatter(currency);

            DefaultCurrencyTextblock.Text = defaultCurrencyFormatter.Format(1234.56);

            // Create currency formatter for USD
            CurrencyFormatter usdCurrencyFormatter = new CurrencyFormatter("USD");

            USDCurrencyTextblock.Text = usdCurrencyFormatter.Format(1234.56);

            // Create currency formatter for EUR
            CurrencyFormatter eurITCurrencyFormatter = new CurrencyFormatter("EUR", new[] { "it-IT" }, "IT");

            EurItCurrencyTextblock.Text = eurITCurrencyFormatter.Format(1234.56);
        }
Ejemplo n.º 2
0
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            // 百分比格式化
            PercentFormatter percentFormatter = new PercentFormatter();

            // PercentFormatter percentFormatter = new PercentFormatter(new[] { "zh-Hans-CN" }, "CN");
            lblMsg.Text  = percentFormatter.Format(3.1415926);
            lblMsg.Text += Environment.NewLine;

            // 千分比格式化
            PermilleFormatter permilleFormatter = new PermilleFormatter();

            //  PermilleFormatter permilleFormatter = new PermilleFormatter(new[] { "zh-Hans-CN" }, "CN");
            lblMsg.Text += permilleFormatter.Format(3.1415926);
            lblMsg.Text += Environment.NewLine;

            // 数字格式化
            DecimalFormatter decimalFormatter = new DecimalFormatter();

            // DecimalFormatter decimalFormatter = new DecimalFormatter(new[] { "zh-Hans-CN" }, "CN");
            lblMsg.Text += decimalFormatter.Format(3.1415926);
            lblMsg.Text += Environment.NewLine;

            // 货币格式化
            CurrencyFormatter currencyFormatter = new CurrencyFormatter("CNY");

            // CurrencyFormatter currencyFormatter = new CurrencyFormatter("CNY", new[] { "zh-Hans-CN" }, "CN");
            lblMsg.Text += currencyFormatter.Format(3.1415926);
        }
        public void Format_WhenCalled_ReturnsCorrectFormat()
        {
            var value     = 10.1234m;
            var formatter = new DecimalFormatter("0.00");

            var actual = formatter.Format(value);

            actual.Should().Be("10.12");
        }
Ejemplo n.º 4
0
        public void Format_Test_format_with_two_decimal_places()
        {
            var value = 10.1234m;

            var target = new DecimalFormatter("0.00");

            var actual = target.Format(value);

            Assert.AreEqual("10.12", actual);
        }
Ejemplo n.º 5
0
    private string GenerateValue_ValueString(string resourceString, double ratingValue)
    {
        DecimalFormatter formatter             = new DecimalFormatter();
        SignificantDigitsNumberRounder rounder = new SignificantDigitsNumberRounder();

        formatter.NumberRounder = rounder;

        string maxRatingString = GetRatingControl().MaxRating.ToString();

        int fractionDigits = DetermineFractionDigits(ratingValue);
        int sigDigits      = DetermineSignificantDigits(ratingValue, fractionDigits);

        formatter.FractionDigits  = fractionDigits;
        rounder.SignificantDigits = (uint)sigDigits;
        string ratingString = formatter.Format(ratingValue);

        return(StringUtil.FormatString(resourceString, ratingString, maxRatingString));
    }
        /// <summary>
        /// This is the click handler for the 'Display' button.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Display_Click(object sender, RoutedEventArgs e)
        {
            // This scenario uses the Windows.Globalization.NumberFormatting.DecimalFormatter,
            // Windows.Globalization.NumberFormatting.CurrencyFormatter and
            // Windows.Globalization.NumberFormatting.PercentFormatter classes to format and parse a number
            // percentage or currency.

            // Keep results of the scenario in a StringBuilder
            StringBuilder results = new StringBuilder();

            // Define percent formatters.
            PercentFormatter percentFormat   = new PercentFormatter();
            PercentFormatter percentFormatJP = new PercentFormatter(new string[] { "ja" }, "ZZ");
            PercentFormatter percentFormatFR = new PercentFormatter(new string[] { "fr-FR" }, "ZZ");

            // Define decimal formatters.
            DecimalFormatter decimalFormat = new DecimalFormatter();

            decimalFormat.IsGrouped = true;
            DecimalFormatter decimalFormatJP = new DecimalFormatter(new string[] { "ja" }, "ZZ");

            decimalFormatJP.IsGrouped = true;
            DecimalFormatter decimalFormatFR = new DecimalFormatter(new string[] { "fr-FR" }, "ZZ");

            decimalFormatFR.IsGrouped = true;

            // Define currency formatters
            string            userCurrency     = GlobalizationPreferences.Currencies[0];
            CurrencyFormatter currencyFormat   = new CurrencyFormatter(userCurrency);
            CurrencyFormatter currencyFormatJP = new CurrencyFormatter("JPY", new string[] { "ja" }, "ZZ");
            CurrencyFormatter currencyFormatFR = new CurrencyFormatter("EUR", new string[] { "fr-FR" }, "ZZ");

            // Generate numbers for parsing.
            double percentNumber  = 0.523;
            double decimalNumber  = 12345.67;
            double currencyNumber = 1234.56;

            // Roundtrip the percent numbers by formatting and parsing.
            String percent1       = percentFormat.Format(percentNumber);
            double percent1Parsed = percentFormat.ParseDouble(percent1).Value;

            String percent1JP       = percentFormatJP.Format(percentNumber);
            double percent1JPParsed = percentFormatJP.ParseDouble(percent1JP).Value;

            String percent1FR       = percentFormatFR.Format(percentNumber);
            double percent1FRParsed = percentFormatFR.ParseDouble(percent1FR).Value;

            // Generate the results for percent parsing.
            results.AppendLine("Percent parsing of " + percentNumber);
            results.AppendLine("Formatted for current user: "******" Parsed as current user: "******"Formatted for ja-JP: " + percent1JP + " Parsed for ja-JP: " + percent1JPParsed);
            results.AppendLine("Formatted for fr-FR: " + percent1FR + " Parsed for fr-FR: " + percent1FRParsed);
            results.AppendLine();

            // Roundtrip the decimal numbers for formatting and parsing.
            String decimal1       = decimalFormat.Format(decimalNumber);
            double decimal1Parsed = decimalFormat.ParseDouble(decimal1).Value;

            String decimal1JP       = decimalFormatJP.Format(decimalNumber);
            double decimal1JPParsed = decimalFormatJP.ParseDouble(decimal1JP).Value;

            String decimal1FR       = decimalFormatFR.Format(decimalNumber);
            double decimal1FRParsed = decimalFormatFR.ParseDouble(decimal1FR).Value;

            // Generate the results for decimal parsing.
            results.AppendLine("Decimal parsing of " + decimalNumber);
            results.AppendLine("Formatted for current user: "******" Parsed as current user: "******"Formatted for ja-JP: " + decimal1JP + " Parsed for ja-JP: " + decimal1JPParsed);
            results.AppendLine("Formatted for fr-FR: " + decimal1FR + " Parsed for fr-FR: " + decimal1FRParsed);
            results.AppendLine();

            // Roundtrip the currency numbers for formatting and parsing.
            String currency1       = currencyFormat.Format(currencyNumber);
            double currency1Parsed = currencyFormat.ParseDouble(currency1).Value;

            String currency1JP       = currencyFormatJP.Format(currencyNumber);
            double currency1JPParsed = currencyFormatJP.ParseDouble(currency1JP).Value;

            String currency1FR       = currencyFormatFR.Format(currencyNumber);
            double currency1FRParsed = currencyFormatFR.ParseDouble(currency1FR).Value;

            // Generate the results for decimal parsing.
            results.AppendLine("Currency parsing of " + currencyNumber);
            results.AppendLine("Formatted for current user: "******" Parsed as current user: "******"Formatted for ja-JP: " + currency1JP + " Parsed for ja-JP: " + currency1JPParsed);
            results.AppendLine("Formatted for fr-FR: " + currency1FR + " Parsed for fr-FR: " + currency1FRParsed);
            results.AppendLine();

            // Display the results.
            OutputTextBlock.Text = results.ToString();
        }
Ejemplo n.º 7
0
            public override object Invoke(XsltContext xsltContext, object[] args, XPathNavigator docContext)
            {
                DecimalFormat formatInfo = ((XsltCompileContext)xsltContext).ResolveFormatName(args.Length == 3 ? ToString(args[2]) : null);

                return(DecimalFormatter.Format(ToNumber(args[0]), ToString(args[1]), formatInfo));
            }
Ejemplo n.º 8
0
        private async Task GetMapSizes()
        {
            var mapFiles = await GetMapFiles();

            long totalFileSize = 0;

            foreach (StorageFile mapFile in mapFiles)
            {
                BasicProperties basicProperties = await mapFile.GetBasicPropertiesAsync();

                totalFileSize += Convert.ToInt64(basicProperties.Size);
            }

            double mapSizeInMB = totalFileSize > 0 ? (totalFileSize / 1024.0) / 1024.0 : 0;

            DispatcherHelper.CheckBeginInvokeOnUI(() => MapSizes = $"Currently we have {mapFiles.Count} maps cached, with a total of {_decimalFormat.Format(mapSizeInMB)} MB");
        }
        /// <summary>
        /// This is the click handler for the 'Display' button.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Display_Click(object sender, RoutedEventArgs e)
        {
            // This scenario uses language tags with unicode extensions to construct and use the various
            // formatters and NumeralSystemTranslator in Windows.Globalization.NumberFormatting to format numbers

            // Keep results of the scenario in a StringBuilder
            StringBuilder results = new StringBuilder();

            // Create number to format.
            double randomNumber = (new Random().NextDouble() * 100000);

            results.AppendLine("Random number used by formatters: " + randomNumber);
            // Create a string to translate
            String stringToTranslate = "These are the 10 digits of a numeral system: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9";

            results.AppendLine("String used by NumeralSystemTranslater: " + stringToTranslate);
            // Create the rounder and set its increment to 0.01
            IncrementNumberRounder rounder = new Windows.Globalization.NumberFormatting.IncrementNumberRounder();

            rounder.Increment = 0.001;
            results.AppendLine("CurrencyFormatter will be using Euro symbol and all formatters rounding to 0.001 increments");
            results.AppendLine();

            // The list of language tags with unicode extensions we want to test
            String[] languages = new[] { "de-DE-u-nu-telu-ca-buddist-co-phonebk-cu-usd", "ja-jp-u-nu-arab" };

            // Create the various formatters, now using the language list with unicode extensions
            results.AppendLine("Creating formatters using following languages in the language list:");
            foreach (String language in languages)
            {
                results.AppendLine("\t" + language);
            }
            results.AppendLine();

            // Create the various formatters.
            DecimalFormatter decimalFormatter = new DecimalFormatter(languages, "ZZ");

            decimalFormatter.NumberRounder = rounder; decimalFormatter.FractionDigits = 2;
            CurrencyFormatter currencyFormatter = new CurrencyFormatter(CurrencyIdentifiers.EUR, languages, "ZZ");

            currencyFormatter.NumberRounder = rounder; currencyFormatter.FractionDigits = 2;
            PercentFormatter percentFormatter = new PercentFormatter(languages, "ZZ");

            percentFormatter.NumberRounder = rounder; percentFormatter.FractionDigits = 2;
            PermilleFormatter permilleFormatter = new PermilleFormatter(languages, "ZZ");

            permilleFormatter.NumberRounder = rounder; permilleFormatter.FractionDigits = 2;
            NumeralSystemTranslator numeralTranslator = new NumeralSystemTranslator(languages);

            results.AppendLine("Using resolved language  " + decimalFormatter.ResolvedLanguage + "  : (note that all extension tags other than nu are ignored)");
            // Format using formatters and translate using NumeralSystemTranslator.
            results.AppendLine("Decimal Formatted:   " + decimalFormatter.Format(randomNumber));
            results.AppendLine("Currency formatted:   " + currencyFormatter.Format(randomNumber));
            results.AppendLine("Percent formatted:   " + percentFormatter.Format(randomNumber));
            results.AppendLine("Permille formatted:   " + permilleFormatter.Format(randomNumber));
            results.AppendLine("NumeralTranslator translated:   " + numeralTranslator.TranslateNumerals(stringToTranslate));
            results.AppendLine();

            // Display the results
            rootPage.NotifyUser(results.ToString(), NotifyType.StatusMessage);
        }