Search in sources :

Example 61 with DecimalFormat

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

the class DecimalFormatTest method test_formatLong_minimumIntegerDigits.

public void test_formatLong_minimumIntegerDigits() {
    DecimalFormat df = new DecimalFormat("###0.##", new DecimalFormatSymbols(Locale.US));
    df.setMinimumIntegerDigits(3);
    assertEquals(3, df.getMinimumIntegerDigits());
    assertEquals("012", df.format(12));
    df.setMaximumIntegerDigits(2);
    assertEquals(2, df.getMinimumIntegerDigits());
    assertEquals("00.7", df.format(0.7));
}
Also used : DecimalFormatSymbols(java.text.DecimalFormatSymbols) DecimalFormat(java.text.DecimalFormat)

Example 62 with DecimalFormat

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

the class DecimalFormatTest method test_parse_withParsePosition.

public void test_parse_withParsePosition() {
    DecimalFormat format = (DecimalFormat) NumberFormat.getNumberInstance(Locale.ENGLISH);
    ParsePosition pos = new ParsePosition(0);
    Number result = format.parse("9223372036854775807", pos);
    assertTrue("Wrong result type for Long.MAX_VALUE", result.getClass() == Long.class);
    assertTrue("Wrong result Long.MAX_VALUE", result.longValue() == Long.MAX_VALUE);
    pos = new ParsePosition(0);
    result = format.parse("-9223372036854775808", pos);
    assertTrue("Wrong result type for Long.MIN_VALUE", result.getClass() == Long.class);
    assertTrue("Wrong result Long.MIN_VALUE: " + result.longValue(), result.longValue() == Long.MIN_VALUE);
    pos = new ParsePosition(0);
    result = format.parse("9223372036854775808", pos);
    assertTrue("Wrong result type for Long.MAX_VALUE+1", result.getClass() == Double.class);
    assertTrue("Wrong result Long.MAX_VALUE + 1", result.doubleValue() == (double) Long.MAX_VALUE + 1);
    pos = new ParsePosition(0);
    result = format.parse("-9223372036854775809", pos);
    assertTrue("Wrong result type for Long.MIN_VALUE+1", result.getClass() == Double.class);
    assertTrue("Wrong result Long.MIN_VALUE - 1", result.doubleValue() == (double) Long.MIN_VALUE - 1);
    pos = new ParsePosition(0);
    result = format.parse("18446744073709551629", pos);
    assertTrue("Wrong result type for overflow", result.getClass() == Double.class);
    assertTrue("Wrong result for overflow", result.doubleValue() == 18446744073709551629d);
    pos = new ParsePosition(0);
    result = format.parse("42325917317067571199", pos);
    assertTrue("Wrong result type for overflow a: " + result, result.getClass() == Double.class);
    assertTrue("Wrong result for overflow a: " + result, result.doubleValue() == 42325917317067571199d);
    pos = new ParsePosition(0);
    result = format.parse("4232591731706757119E1", pos);
    assertTrue("Wrong result type for overflow b: " + result, result.getClass() == Double.class);
    assertTrue("Wrong result for overflow b: " + result, result.doubleValue() == 42325917317067571190d);
    pos = new ParsePosition(0);
    result = format.parse(".42325917317067571199E20", pos);
    assertTrue("Wrong result type for overflow c: " + result, result.getClass() == Double.class);
    assertTrue("Wrong result for overflow c: " + result, result.doubleValue() == 42325917317067571199d);
    pos = new ParsePosition(0);
    result = format.parse("922337203685477580.9E1", pos);
    assertTrue("Wrong result type for overflow d: " + result, result.getClass() == Double.class);
    assertTrue("Wrong result for overflow d: " + result, result.doubleValue() == 9223372036854775809d);
    pos = new ParsePosition(0);
    result = format.parse("9.223372036854775809E18", pos);
    assertTrue("Wrong result type for overflow e: " + result, result.getClass() == Double.class);
    assertTrue("Wrong result for overflow e: " + result, result.doubleValue() == 9223372036854775809d);
}
Also used : DecimalFormat(java.text.DecimalFormat) ParsePosition(java.text.ParsePosition)

Example 63 with DecimalFormat

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

the class DecimalFormatTest method test_getNegativeSuffix.

public void test_getNegativeSuffix() {
    DecimalFormat df = new DecimalFormat();
    df.setNegativeSuffix("&");
    assertTrue("Incorrect negative suffix", df.getNegativeSuffix().equals("&"));
}
Also used : DecimalFormat(java.text.DecimalFormat)

Example 64 with DecimalFormat

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

the class DecimalFormatTest method test_getPositiveSuffix.

public void test_getPositiveSuffix() {
    DecimalFormat df = new DecimalFormat();
    df.setPositiveSuffix("%");
    assertTrue("Incorrect positive prefix", df.getPositiveSuffix().equals("%"));
}
Also used : DecimalFormat(java.text.DecimalFormat)

Example 65 with DecimalFormat

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

the class DecimalFormatTest method testConstructor_stringAndSymbols.

public void testConstructor_stringAndSymbols() {
    // case 1: Try to construct object using correct pattern and format
    // symbols.
    DecimalFormatSymbols dfs = new DecimalFormatSymbols(Locale.CANADA);
    DecimalFormat format1 = new DecimalFormat("'$'1000.0000", dfs);
    DecimalFormat format2 = new DecimalFormat();
    format2.applyPattern("'$'1000.0000");
    format2.setDecimalFormatSymbols(dfs);
    assertTrue("Constructed format did not match applied format object", format2.equals(format1));
    assertTrue("Constructed format did not match applied format object", !format1.equals(new DecimalFormat("'$'1000.0000", new DecimalFormatSymbols(Locale.CHINA))));
    // case 2: Try to construct object using null arguments.
    try {
        new DecimalFormat("'$'1000.0000", (DecimalFormatSymbols) null);
        fail();
    } catch (NullPointerException expected) {
    }
    try {
        new DecimalFormat(null, new DecimalFormatSymbols());
        fail();
    } catch (NullPointerException expected) {
    }
    try {
        new DecimalFormat(null, (DecimalFormatSymbols) null);
        fail();
    } catch (NullPointerException expected) {
    }
    // case 3: Try to construct object using incorrect pattern.
    try {
        new DecimalFormat("$'", new DecimalFormatSymbols());
        fail();
    } catch (IllegalArgumentException expected) {
    }
}
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