Package com.ibm.icu.text

Examples of com.ibm.icu.text.DecimalFormat


        return dfs;
    }

    private static DecimalFormat getCannedDecimalFormat(String pattern, ULocale uloc)
    {
        return new DecimalFormat(pattern, getCannedDecimalFormatSymbols(uloc));
    }
View Full Code Here


    public static class DecimalFormatHandler extends NumberFormatHandler
    {
        public Object[] getTestObjects()
        {
            Locale locales[] = SerializableTest.getLocales();
            DecimalFormat formats[] = new DecimalFormat[locales.length];
           
            for (int i = 0; i < locales.length; i += 1) {
                ULocale uloc = ULocale.forLocale(locales[i]);
               
                formats[i] = getCannedDecimalFormat("#,##0.###", uloc);
View Full Code Here

    }

    public void TestBug3()
    {
        double myNumber = -123456;
        DecimalFormat form = null;
        Locale locale[] = {
            new Locale("ar", "", ""),
            new Locale("be", "", ""),
            new Locale("bg", "", ""),
            new Locale("ca", "", ""),
            new Locale("cs", "", ""),
            new Locale("da", "", ""),
            new Locale("de", "", ""),
            new Locale("de", "AT", ""),
            new Locale("de", "CH", ""),
            new Locale("el", "", ""),       // 10
            new Locale("en", "CA", ""),
            new Locale("en", "GB", ""),
            new Locale("en", "IE", ""),
            new Locale("en", "US", ""),
            new Locale("es", "", ""),
            new Locale("et", "", ""),
            new Locale("fi", "", ""),
            new Locale("fr", "", ""),
            new Locale("fr", "BE", ""),
            new Locale("fr", "CA", ""),     // 20
            new Locale("fr", "CH", ""),
            new Locale("he", "", ""),
            new Locale("hr", "", ""),
            new Locale("hu", "", ""),
            new Locale("is", "", ""),
            new Locale("it", "", ""),
            new Locale("it", "CH", ""),
            new Locale("ja", "", ""),
            new Locale("ko", "", ""),
            new Locale("lt", "", ""),       // 30
            new Locale("lv", "", ""),
            new Locale("mk", "", ""),
            new Locale("nl", "", ""),
            new Locale("nl", "BE", ""),
            new Locale("no", "", ""),
            new Locale("pl", "", ""),
            new Locale("pt", "", ""),
            new Locale("ro", "", ""),
            new Locale("ru", "", ""),
            new Locale("sh", "", ""),       // 40
            new Locale("sk", "", ""),
            new Locale("sl", "", ""),
            new Locale("sq", "", ""),
            new Locale("sr", "", ""),
            new Locale("sv", "", ""),
            new Locale("tr", "", ""),
            new Locale("uk", "", ""),
            new Locale("zh", "", ""),
            new Locale("zh", "TW", "")      // 49
        };
        StringBuffer buffer = new StringBuffer();
        ParsePosition parsePos = new ParsePosition(0);
        int i;
        for (i= 0; i < 49; i++) {
    //        form = (DecimalFormat)NumberFormat.getCurrencyInstance(locale[i]);
            form = (DecimalFormat)NumberFormat.getInstance(locale[i]);
            if (form == null) {
                errln("Number format creation failed for " + locale[i].getDisplayName());
                continue;
            }
            FieldPosition pos = new FieldPosition(0);
            buffer.setLength(0);
            form.format(myNumber, buffer, pos);
            parsePos.setIndex(0);
            Object result = form.parse(buffer.toString(), parsePos);
            logln(locale[i].getDisplayName() + " -> " + result);
            if (parsePos.getIndex() != buffer.length()) {
                errln("Number format parse failed.");
            }
        }
View Full Code Here

    // named arguments.
    public void testNumericOnlyMethods() {
        MessageFormat msg = new MessageFormat("Number of files: {numfiles}");
        boolean gotException = false;
        try {
            Format fmts[] = {new DecimalFormat()};
            msg.setFormatsByArgumentIndex(fmts);
        } catch (IllegalArgumentException e) {
            gotException = true;
        }
        if (!gotException) {
            errln("MessageFormat.setFormatsByArgumentIndex() should throw an " +
                  "IllegalArgumentException when called on formats with " +
                  "named arguments but did not!");
        }
       
        gotException = false;
        try {
            msg.setFormatByArgumentIndex(0, new DecimalFormat());
        } catch (IllegalArgumentException e) {
            gotException = true;
        }
        if (!gotException) {
            errln("MessageFormat.setFormatByArgumentIndex() should throw an " +
View Full Code Here

        }
    }
   
    public void TestSetFormat() {
        MessageFormat ms = new MessageFormat("{number} {date}", ULocale.ENGLISH);
        final DecimalFormat decimalFormat = new DecimalFormat("000.000", DecimalFormatSymbols.getInstance(ULocale.ENGLISH));
        ms.setFormatByArgumentName("number", decimalFormat);
        final SimpleDateFormat dateFormat = new SimpleDateFormat("'year:'yy 'month:'MM 'day:'dd");
        dateFormat.setTimeZone(TimeZone.getTimeZone("Etc/GMT"));
        ms.setFormatByArgumentName("date", dateFormat);
        Map map = new HashMap();
View Full Code Here

            result.setCurrency(currency);
            return result;
        }

        // ugly work-around for 2.4
        DecimalFormat result = (DecimalFormat)NumberFormat.getCurrencyInstance(displayLocale);
        HackCurrencyInfo hack = (HackCurrencyInfo)(hackData.get(currency.getCurrencyCode()));
        result.setMinimumFractionDigits(hack.decimals);
        result.setMaximumFractionDigits(hack.decimals);
        result.setRoundingIncrement(hack.rounding);
        DecimalFormatSymbols symbols = result.getDecimalFormatSymbols();
        symbols.setCurrencySymbol(hack.symbol);
        result.setDecimalFormatSymbols(symbols);
        return result;
    }
View Full Code Here

       
    /*
     * Test method for 'com.ibm.icu.text.DecimalFormat.clone()'
     */
    public void testClone() {
        DecimalFormat df = new DecimalFormat("#,#0.00");
        DecimalFormat df2 = new DecimalFormat("#,#0.00");
        DecimalFormat dfn = new DecimalFormat("#,#0.00");
        dfn.setNegativePrefix(dfn.getNegativePrefix() + '!');
        testEHCS(df, df2, dfn);
    }
View Full Code Here

    /*
     * Test method for 'com.ibm.icu.text.DecimalFormat.DecimalFormat()'
     */
    public void testDecimalFormat() {
        DecimalFormat df = new DecimalFormat();
        assertEquals("9,223,372,036,854,775,807", df.format(lmax));
    }
View Full Code Here

    /*
     * Test method for 'com.ibm.icu.text.DecimalFormat.DecimalFormat(String)'
     */
    public void testDecimalFormatString() {
        DecimalFormat df = new DecimalFormat("#,##0.000");
        assertEquals("23.330", df.format(dsmall));
    }
View Full Code Here

    /*
     * Test method for 'com.ibm.icu.text.DecimalFormat.DecimalFormat(String, DecimalFormatSymbols)'
     */
    public void testDecimalFormatStringDecimalFormatSymbols() {
        DecimalFormatSymbols sym = new DecimalFormatSymbols(Locale.FRANCE);
        DecimalFormat df = new DecimalFormat("#,##0.000", sym);
        assertEquals("23,330", df.format(dsmall));
    }
View Full Code Here

TOP

Related Classes of com.ibm.icu.text.DecimalFormat

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.