Code example for DecimalFormat

Methods: parsesetParseBigDecimal, setParseIntegerOnly

0
    } 
 
    // Test the type of the returned object 
    public void test_parseLjava_lang_String_Ljava_text_ParsePosition() { 
        DecimalFormat form = (DecimalFormat) DecimalFormat.getInstance(Locale.US);
        form.setParseIntegerOnly(true);
        form.setParseBigDecimal(true);
 
        final String doubleMax2 = "359,538,626,972,463,141,629,054,847,463,408,"
            + "713,596,141,135,051,689,993,197,834,953,606,314,521,560,057,077," 
            + "521,179,117,265,533,756,343,080,917,907,028,764,928,468,642,653," 
            + "778,928,365,536,935,093,407,075,033,972,099,821,153,102,564,152," 
            + "490,980,180,778,657,888,151,737,016,910,267,884,609,166,473,806," 
            + "445,896,331,617,118,664,246,696,549,595,652,408,289,446,337,476," 
            + "354,361,838,599,762,500,808,052,368,249,716,736"; 
        Number number = form.parse(doubleMax2, new ParsePosition(0));
        assertTrue(number instanceof BigDecimal);
        BigDecimal result = (BigDecimal)number;
        assertEquals(new BigDecimal(Double.MAX_VALUE).add(new BigDecimal(
                Double.MAX_VALUE)), result);
    } 
Stop searching for code, let great code find you!  Add Codota to your java IDE