Search in sources :

Example 36 with DecimalFormat

use of java.text.DecimalFormat in project j2objc by google.

the class DecimalFormatTest method testMaximumFactionDigits_maxChangesMin.

// When MinFractionDigits is set first and less than MaxFractionDigits, min
// will be changed to max value
public void testMaximumFactionDigits_maxChangesMin() {
    DecimalFormat form = (DecimalFormat) NumberFormat.getInstance(Locale.US);
    form.setMinimumFractionDigits(200);
    form.setMaximumFractionDigits(100);
    assertEquals(100, form.getMaximumFractionDigits());
    assertEquals(100, form.getMinimumFractionDigits());
    form.setMinimumIntegerDigits(200);
    form.setMaximumIntegerDigits(100);
    assertEquals(100, form.getMaximumIntegerDigits());
    assertEquals(100, form.getMinimumIntegerDigits());
}
Also used : DecimalFormat(java.text.DecimalFormat)

Example 37 with DecimalFormat

use of java.text.DecimalFormat in project j2objc by google.

the class DecimalFormatTest method test_setCurrency.

public void test_setCurrency() {
    Locale locale = Locale.CANADA;
    DecimalFormat df = ((DecimalFormat) NumberFormat.getCurrencyInstance(locale));
    try {
        df.setCurrency(null);
        fail("Expected NullPointerException");
    } catch (NullPointerException e) {
    }
    Currency currency = Currency.getInstance("AED");
    df.setCurrency(currency);
    assertTrue("Returned incorrect currency", currency == df.getCurrency());
    assertEquals("Returned incorrect currency symbol", currency.getSymbol(locale), df.getDecimalFormatSymbols().getCurrencySymbol());
    assertEquals("Returned incorrect international currency symbol", currency.getCurrencyCode(), df.getDecimalFormatSymbols().getInternationalCurrencySymbol());
}
Also used : Locale(java.util.Locale) DecimalFormat(java.text.DecimalFormat) Currency(java.util.Currency)

Example 38 with DecimalFormat

use of java.text.DecimalFormat in project j2objc by google.

the class DecimalFormatTest method test_setDecimalSeparatorAlwaysShown.

public void test_setDecimalSeparatorAlwaysShown() {
    DecimalFormat df = new DecimalFormat("###0.##", new DecimalFormatSymbols(Locale.US));
    assertEquals("Wrong default result", "5", df.format(5));
    df.setDecimalSeparatorAlwaysShown(true);
    assertTrue("Not set", df.isDecimalSeparatorAlwaysShown());
    assertEquals("Wrong set result", "7.", df.format(7));
}
Also used : DecimalFormatSymbols(java.text.DecimalFormatSymbols) DecimalFormat(java.text.DecimalFormat)

Example 39 with DecimalFormat

use of java.text.DecimalFormat in project j2objc by google.

the class DecimalFormatTest method test_toPattern.

public void test_toPattern() {
    DecimalFormat format = new DecimalFormat();
    format.applyPattern("#.#");
    assertEquals("Wrong pattern 1", "#0.#", format.toPattern());
    format.applyPattern("#.");
    assertEquals("Wrong pattern 2", "#0.", format.toPattern());
    format.applyPattern("#");
    assertEquals("Wrong pattern 3", "#", format.toPattern());
    format.applyPattern(".#");
    assertEquals("Wrong pattern 4", "#.0", format.toPattern());
}
Also used : DecimalFormat(java.text.DecimalFormat)

Example 40 with DecimalFormat

use of java.text.DecimalFormat in project j2objc by google.

the class DecimalFormatTest method test_setDecimalFormatSymbols.

/* J2ObjC: Android behavior differs from RI.
    public void test_parse_withMultiplier() {
        DecimalFormat format = (DecimalFormat) NumberFormat.getNumberInstance(Locale.ENGLISH);
        Number result;

        format.setMultiplier(100);
        result = format.parse("9223372036854775807", new ParsePosition(0));
        assertEquals("Wrong result type multiplier 100: " + result, Double.class,
                result.getClass());
        assertEquals("Wrong result for multiplier 100: " + result,
                92233720368547758.07d, result.doubleValue());

        format.setMultiplier(1000);
        result = format.parse("9223372036854775807", new ParsePosition(0));
        assertEquals("Wrong result type multiplier 1000: " + result, Double.class,
                result.getClass());
        assertEquals("Wrong result for multiplier 1000: " + result,
                9223372036854775.807d, result.doubleValue());

        format.setMultiplier(10000);
        result = format.parse("9223372036854775807", new ParsePosition(0));
        assertEquals("Wrong result type multiplier 10000: " + result,
                Double.class, result.getClass());
        assertEquals("Wrong result for multiplier 10000: " + result,
                922337203685477.5807d, result.doubleValue());
    }*/
public void test_setDecimalFormatSymbols() {
    DecimalFormat df = new DecimalFormat("###0.##");
    DecimalFormatSymbols dfs = new DecimalFormatSymbols();
    dfs.setDecimalSeparator('@');
    df.setDecimalFormatSymbols(dfs);
    assertTrue("Not set", df.getDecimalFormatSymbols().equals(dfs));
    assertEquals("Symbols not used", "1@2", df.format(1.2));
    // The returned symbols may be cloned in two spots
    // 1. When set
    // 2. When returned
    DecimalFormat format = new DecimalFormat();
    DecimalFormatSymbols symbols = new DecimalFormatSymbols();
    format.setDecimalFormatSymbols(symbols);
    DecimalFormatSymbols symbolsOut = format.getDecimalFormatSymbols();
    assertNotSame(symbols, symbolsOut);
}
Also used : DecimalFormatSymbols(java.text.DecimalFormatSymbols) DecimalFormat(java.text.DecimalFormat)

Aggregations

DecimalFormat (java.text.DecimalFormat)823 DecimalFormatSymbols (java.text.DecimalFormatSymbols)94 NumberFormat (java.text.NumberFormat)93 IOException (java.io.IOException)48 BigDecimal (java.math.BigDecimal)47 ArrayList (java.util.ArrayList)44 IFormatterTextCallBack (org.xclcharts.common.IFormatterTextCallBack)33 ParseException (java.text.ParseException)31 Test (org.junit.Test)31 File (java.io.File)29 IFormatterDoubleCallBack (org.xclcharts.common.IFormatterDoubleCallBack)29 Support_DecimalFormat (tests.support.Support_DecimalFormat)28 Date (java.util.Date)25 SimpleDateFormat (java.text.SimpleDateFormat)24 HashMap (java.util.HashMap)24 Locale (java.util.Locale)22 PrintWriter (java.io.PrintWriter)20 UsageVO (com.cloud.usage.UsageVO)19 List (java.util.List)18 JFreeChart (org.jfree.chart.JFreeChart)18