//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test(dataProvider = "patterns") public void test_ofPattern(String pattern, double value, String expected)
        public virtual void test_ofPattern(string pattern, double value, string expected)
        {
            string java   = (new DecimalFormat(pattern, DecimalFormatSymbols.getInstance(Locale.ENGLISH))).format(value);
            string strata = NumberFormatter.ofPattern(pattern, Locale.ENGLISH).format(value);

            assertEquals(strata, java);
            assertEquals(strata, expected);
        }
        public char getDecimalSeparator()
        {
            if (_format == null)
            {
                _format = DecimalFormatSymbols.getInstance(_locale);
            }

            return(_format.getDecimalSeparator());
        }
Beispiel #3
0
            public ScientificFormat(string format, Java.Util.Locale locale)
            {
                DecimalFormatSymbols symbols = new DecimalFormatSymbols(locale)
                {
                    Infinity = "Infinity"
                };

                _format = new DecimalFormat(format, symbols);
            }
Beispiel #4
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public void listSegments() throws java.io.IOException
        public virtual void listSegments()
        {
            DecimalFormat formatter = new DecimalFormat("###,###.###", DecimalFormatSymbols.getInstance(Locale.ROOT));

            for (int x = 0; x < infos.size(); x++)
            {
                SegmentCommitInfo info    = infos.info(x);
                string            sizeStr = formatter.format(info.sizeInBytes());
                Console.WriteLine(info.info.name + " " + sizeStr);
            }
        }
        static char GetDecimalSeparator()
        {
            var format = NumberFormat.Instance as DecimalFormat;

            if (format == null)
            {
                return('.');
            }

            DecimalFormatSymbols sym = format.DecimalFormatSymbols;

            return(sym.DecimalSeparator);
        }
Beispiel #6
0
	    internal NumberFormatInfo(Locale locale)
	    {
	        _locale = locale;

	        _numbers = NumberFormat.GetNumberInstance(locale);

            _symbols = new DecimalFormatSymbols(locale) { Infinity = "Infinity" };
	        
            _decimals = _numbers as DecimalFormat ?? new DecimalFormat();
            _decimals.DecimalFormatSymbols = _symbols;

            _currency =  NumberFormat.GetCurrencyInstance(locale) as DecimalFormat ?? _decimals;
            _percent = NumberFormat.GetPercentInstance(locale) as DecimalFormat ?? _decimals;
        }
Beispiel #7
0
        private static DecimalStyle Create(Locale locale)
        {
            DecimalFormatSymbols oldSymbols = DecimalFormatSymbols.GetInstance(locale);
            char zeroDigit        = oldSymbols.ZeroDigit;
            char positiveSign     = '+';
            char negativeSign     = oldSymbols.MinusSign;
            char decimalSeparator = oldSymbols.DecimalSeparator;

            if (zeroDigit == '0' && negativeSign == '-' && decimalSeparator == '.')
            {
                return(STANDARD);
            }
            return(new DecimalStyle(zeroDigit, positiveSign, negativeSign, decimalSeparator));
        }
Beispiel #8
0
        private static NumberFormat CreateFormat(Entry type)
        {
            var locale = type.FormatProvider.ToLocale();

            if (type.FormatType == FormatHex)
            {
                return(new HexFormat(type.Digits, type.IsUpperCase));
            }

            if (type.FormatType == FormatScientific)
            {
                var pattern = type.Pattern;
                if (pattern == null)
                {
                    pattern = GetPatternByDigits(type.Digits) + (type.IsUpperCase ? "E0" : "e0");
                }
                return(new ScientificFormat(pattern, locale));
            }

            if (type.FormatType == FormatDecimal)
            {
                DecimalFormatSymbols symbols = new DecimalFormatSymbols(locale)
                {
                    Infinity = "Infinity"
                };
                string pattern = type.Pattern ?? GetPatternByDigits(type.Digits);
                return(new DecimalFormat(pattern, symbols));
            }

            if (type.FormatType == FormatCurrency)
            {
                return(NumberFormat.GetCurrencyInstance(locale));
            }

            // default
            var format = NumberFormat.GetNumberInstance(locale);

            if (type.Pattern != null)
            {
                var decf = format as DecimalFormat;
                if (decf != null)
                {
                    decf.ApplyLocalizedPattern(type.Pattern);
                }
            }

            return(format);
        }
Beispiel #9
0
        internal NumberFormatInfo(Locale locale)
        {
            _locale = locale;

            _numbers = NumberFormat.GetNumberInstance(locale);

            _symbols = new DecimalFormatSymbols(locale)
            {
                Infinity = "Infinity"
            };

            _decimals = _numbers as DecimalFormat ?? new DecimalFormat();
            _decimals.DecimalFormatSymbols = _symbols;

            _currency = NumberFormat.GetCurrencyInstance(locale) as DecimalFormat ?? _decimals;
            _percent  = NumberFormat.GetPercentInstance(locale) as DecimalFormat ?? _decimals;
        }
        private BigDecimal nDigitFormat(BigDecimal value, int scale)
        {
            /*
             * I needed 123,45, locale independent.I tried
             * NumberFormat.getCurrencyInstance().format( 12345.6789 ); but that is
             * locale specific.I also tried DecimalFormat df = new DecimalFormat(
             * "0,00" ); df.setDecimalSeparatorAlwaysShown(true);
             * df.setGroupingUsed(false); DecimalFormatSymbols symbols = new
             * DecimalFormatSymbols(); symbols.setDecimalSeparator(',');
             * symbols.setGroupingSeparator(' ');
             * df.setDecimalFormatSymbols(symbols);
             *
             * but that would not switch off grouping. Although I liked very much
             * the (incomplete) "BNF diagram" in
             * http://docs.oracle.com/javase/tutorial/i18n/format/decimalFormat.html
             * in the end I decided to calculate myself and take eur+sparator+cents
             *
             * This function will cut off, i.e. floor() subcent values Tests:
             * System.err.println(utils.currencyFormat(new BigDecimal(0),
             * ".")+"\n"+utils.currencyFormat(new BigDecimal("-1.10"),
             * ",")+"\n"+utils.currencyFormat(new BigDecimal("-1.1"),
             * ",")+"\n"+utils.currencyFormat(new BigDecimal("-1.01"),
             * ",")+"\n"+utils.currencyFormat(new BigDecimal("20000123.3489"),
             * ",")+"\n"+utils.currencyFormat(new BigDecimal("20000123.3419"),
             * ",")+"\n"+utils.currencyFormat(new BigDecimal("12"), ","));
             *
             * results 0.00 -1,10 -1,10 -1,01 20000123,34 20000123,34 12,00
             */
            value = value.setScale(scale, BigDecimal.ROUND_HALF_UP); // first, round
                                                                     // so that
                                                                     // e.g.
                                                                     // 1.189999999999999946709294817992486059665679931640625
                                                                     // becomes
                                                                     // 1.19
            char[] repeat = new char[scale];
            Arrays.fill(repeat, '0');

            DecimalFormatSymbols otherSymbols = new DecimalFormatSymbols();

            otherSymbols.setDecimalSeparator('.');
            DecimalFormat dec = new DecimalFormat("0." + new String(repeat),
                                                  otherSymbols);

            return(new BigDecimal(dec.format(value)));
        }
Beispiel #11
0
 //-------------------------------------------------------------------------
 /// <summary>
 /// Obtains a formatter based on a pattern in the specified locale.
 /// </summary>
 /// <param name="pattern">  the pattern string to use </param>
 /// <param name="locale">  the locale to use </param>
 /// <returns> the formatter </returns>
 /// <exception cref="IllegalArgumentException"> if the pattern is invalid </exception>
 /// <seealso cref= DecimalFormat </seealso>
 public static NumberFormatter ofPattern(string pattern, Locale locale)
 {
     ArgChecker.notNull(pattern, "pattern");
     ArgChecker.notNull(locale, "locale");
     return(new NumberFormatter(new DecimalFormat(pattern, DecimalFormatSymbols.getInstance(locale))));
 }