Search in sources :

Example 56 with DecimalFormat

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

the class DecimalFormatTest method test_setDecimalFormatSymbolsAsNull.

public void test_setDecimalFormatSymbolsAsNull() {
    // Regression for HARMONY-1070
    DecimalFormat format = (DecimalFormat) NumberFormat.getInstance();
    format.setDecimalFormatSymbols(null);
}
Also used : DecimalFormat(java.text.DecimalFormat)

Example 57 with DecimalFormat

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

the class DecimalFormatTest method testMinimumIntegerDigits_getAndSet.

public void testMinimumIntegerDigits_getAndSet() {
    final int minIntDigit = 1;
    DecimalFormat form = (DecimalFormat) NumberFormat.getInstance(Locale.US);
    // getMaximumIntegerDigits from DecimalFormat (default to 1)
    assertEquals(minIntDigit, form.getMinimumIntegerDigits());
    form.setMinimumIntegerDigits(300);
    assertEquals(300, form.getMinimumIntegerDigits());
    // Deliberately > 309. The API docs mention 309 and suggest that you can set the value
    // higher but it will use 309 as a ceiling.
    form.setMinimumIntegerDigits(500);
    assertEquals(500, form.getMinimumIntegerDigits());
    form.setMaximumIntegerDigits(400);
    assertEquals(400, form.getMinimumIntegerDigits());
    form.setMinimumIntegerDigits(-3);
    assertEquals(0, form.getMinimumIntegerDigits());
}
Also used : DecimalFormat(java.text.DecimalFormat)

Example 58 with DecimalFormat

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

the class DecimalFormatTest method test_applyPattern.

public void test_applyPattern() {
    DecimalFormat format = new DecimalFormat("#.#");
    assertEquals("Wrong pattern 1", "#0.#", format.toPattern());
    format = new DecimalFormat("#.");
    assertEquals("Wrong pattern 2", "#0.", format.toPattern());
    format = new DecimalFormat("#");
    assertEquals("Wrong pattern 3", "#", format.toPattern());
    format = new DecimalFormat(".#");
    assertEquals("Wrong pattern 4", "#.0", format.toPattern());
    // Regression for HARMONY-6485
    format = new DecimalFormat();
    format.setMinimumIntegerDigits(0);
    format.setMinimumFractionDigits(0);
    format.setMaximumFractionDigits(0);
    format.applyPattern("00.0#");
    assertEquals("Minimum integer digits not set", 2, format.getMinimumIntegerDigits());
    assertEquals("Minimum fraction digits not set", 1, format.getMinimumFractionDigits());
    assertEquals("Maximum fraction digits not set", 2, format.getMaximumFractionDigits());
    try {
        format.applyPattern(null);
        fail();
    } catch (NullPointerException expected) {
    }
    try {
        format.applyPattern("%#,##,###,####'");
        fail();
    } catch (IllegalArgumentException expected) {
    }
    try {
        format.applyPattern("#.##0.00");
        fail();
    } catch (IllegalArgumentException expected) {
    }
}
Also used : DecimalFormat(java.text.DecimalFormat)

Example 59 with DecimalFormat

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

the class DecimalFormatTest method test_formatToCharacterIterator_roundingUnnecessaryArithmeticException.

public void test_formatToCharacterIterator_roundingUnnecessaryArithmeticException() {
    DecimalFormat decimalFormat = (DecimalFormat) DecimalFormat.getInstance(Locale.US);
    decimalFormat.setRoundingMode(RoundingMode.UNNECESSARY);
    decimalFormat.setMaximumFractionDigits(0);
    try {
        // when rounding is needed, but RoundingMode is set to RoundingMode.UNNECESSARY,
        // throw ArithmeticException
        decimalFormat.formatToCharacterIterator(new Double(1.5));
        fail("ArithmeticException expected");
    } catch (ArithmeticException e) {
    // expected
    }
}
Also used : DecimalFormat(java.text.DecimalFormat)

Example 60 with DecimalFormat

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

the class DecimalFormatTest method test_getMultiplier.

public void test_getMultiplier() {
    final int defaultMultiplier = 1;
    DecimalFormat form = (DecimalFormat) NumberFormat.getInstance(Locale.US);
    assertEquals(defaultMultiplier, form.getMultiplier());
    DecimalFormat df = new DecimalFormat("###0.##");
    assertEquals("Wrong unset multiplier", 1, df.getMultiplier());
    df = new DecimalFormat("###0.##%");
    assertEquals("Wrong percent multiplier", 100, df.getMultiplier());
    df = new DecimalFormat("###0.##‰");
    assertEquals("Wrong mille multiplier", 1000, df.getMultiplier());
}
Also used : 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