Search in sources :

Example 76 with DecimalFormat

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

the class DecimalFormatTest method test_setMaximumFractionDigitsAffectsRoundingMode.

public void test_setMaximumFractionDigitsAffectsRoundingMode() throws Exception {
    DecimalFormat df = (DecimalFormat) DecimalFormat.getInstance(Locale.US);
    df.setMaximumFractionDigits(0);
    df.setRoundingMode(RoundingMode.HALF_UP);
    assertEquals("-0", df.format(-0.2));
    df.setMaximumFractionDigits(1);
    assertEquals("-0.2", df.format(-0.2));
}
Also used : DecimalFormat(java.text.DecimalFormat)

Example 77 with DecimalFormat

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

the class DecimalFormatTest method assertDecFmtWithMultiplierAndFractionByLocale.

private void assertDecFmtWithMultiplierAndFractionByLocale(String value, int multiplier, int fraction, Locale locale, String expectedResult) {
    DecimalFormat df = (DecimalFormat) NumberFormat.getIntegerInstance(locale);
    df.setMultiplier(multiplier);
    df.setMaximumFractionDigits(fraction);
    BigDecimal d = new BigDecimal(value);
    assertEquals(expectedResult, df.format(d));
}
Also used : DecimalFormat(java.text.DecimalFormat) BigDecimal(java.math.BigDecimal)

Example 78 with DecimalFormat

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

the class DecimalFormatTest method testSetCurrencySymbol.

// Test that overriding the currency symbol survives a roundrip through the
// DecimalFormat constructor.
// http://b/28732330
public void testSetCurrencySymbol() {
    DecimalFormatSymbols decimalFormatSymbols = new DecimalFormatSymbols(Locale.US);
    decimalFormatSymbols.setCurrencySymbol("¥");
    DecimalFormat decimalFormat = new DecimalFormat("¤#,##0.00", decimalFormatSymbols);
    assertEquals("¥", decimalFormat.getDecimalFormatSymbols().getCurrencySymbol());
}
Also used : DecimalFormatSymbols(java.text.DecimalFormatSymbols) DecimalFormat(java.text.DecimalFormat)

Example 79 with DecimalFormat

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

the class DecimalFormatTest method test_exponentSeparator.

public void test_exponentSeparator() throws Exception {
    DecimalFormat df = new DecimalFormat("0E0");
    assertEquals("1E4", df.format(12345.));
    DecimalFormatSymbols dfs = df.getDecimalFormatSymbols();
    dfs.setExponentSeparator("-useless-api-");
    df.setDecimalFormatSymbols(dfs);
    assertEquals("1-useless-api-4", df.format(12345.));
}
Also used : DecimalFormatSymbols(java.text.DecimalFormatSymbols) DecimalFormat(java.text.DecimalFormat)

Example 80 with DecimalFormat

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

the class DecimalFormatTest method testBug15081434.

// Check we don't crash on null inputs.
public void testBug15081434() throws Exception {
    DecimalFormat df = (DecimalFormat) NumberFormat.getCurrencyInstance(Locale.US);
    try {
        df.parse(null);
        fail();
    } catch (NullPointerException expected) {
    }
    try {
        df.applyLocalizedPattern(null);
        fail();
    } catch (NullPointerException expected) {
    }
    try {
        df.applyPattern(null);
        fail();
    } catch (NullPointerException expected) {
    }
    try {
        df.applyPattern(null);
        fail();
    } catch (NullPointerException expected) {
    }
    try {
        df.format(null, new StringBuffer(), new FieldPosition(0));
        fail();
    // J2ObjC: Java docs actually specify that IAE is thrown for null input, not NPE.
    } catch (IllegalArgumentException expected) {
    }
    try {
        df.parse(null, new ParsePosition(0));
        fail();
    } catch (NullPointerException expected) {
    }
    // This just ignores null.
    df.setDecimalFormatSymbols(null);
    try {
        df.setCurrency(null);
        fail();
    } catch (NullPointerException expected) {
    }
    // These just ignore null.
    df.setNegativePrefix(null);
    df.setNegativeSuffix(null);
    df.setPositivePrefix(null);
    df.setPositiveSuffix(null);
    try {
        df.setRoundingMode(null);
        fail();
    } catch (NullPointerException expected) {
    }
}
Also used : DecimalFormat(java.text.DecimalFormat) FieldPosition(java.text.FieldPosition) ParsePosition(java.text.ParsePosition)

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