Code example for DecimalFormat

Methods: isParseBigDecimalsetParseBigDecimalparse, isParseIntegerOnly

0
    public void test_isParseBigDecimalLjava_lang_Boolean_isParseIntegerOnlyLjava_lang_Boolean() { 
 
        // parseBigDecimal default to false 
        DecimalFormat form = (DecimalFormat) DecimalFormat
                .getInstance(Locale.US);
        assertFalse(form.isParseBigDecimal());
        form.setParseBigDecimal(true);
        assertTrue(form.isParseBigDecimal());
 
        try { 
            Number result = form.parse("123.123");
            assertEquals(new BigDecimal("123.123"), result);
        } catch (ParseException e) {
            fail("ParseException was thrown.");
        } 
 
        form.setParseBigDecimal(false);
        assertFalse(form.isParseBigDecimal());
 
        try { 
            Number result = form.parse("123.123");
            assertFalse(result instanceof BigDecimal);
        } catch (ParseException e) {
            fail("ParseException was thrown.");
        } 
 
        // parseIntegerOnly default to false 
        assertFalse(form.isParseIntegerOnly());
    } 
 
    public void test_isParseIntegerOnly() { 
 
            DecimalFormat format = new DecimalFormat();
Stop searching for code, let great code find you!  Add Codota to your java IDE