Code example for BigDecimal

Methods: toString

0
     * when value is not a valid representation of BigDecimal. 
     */ 
    public void testConstrStringException() { 
        String a = "-238768.787678287a+10";
        try { 
            BigDecimal bd = new BigDecimal(a);
            fail("NumberFormatException has not been caught: " + bd.toString());
        } catch (NumberFormatException e) {}
    } 
 
    /** 
     * new BigDecimal(String value, MathContext) 
     */ 
    public void testConstrStringMathContext() { 
        String a = "-238768787678287e214";
        int precision = 5;
        RoundingMode rm = RoundingMode.CEILING;
        MathContext mc = new MathContext(precision, rm);
        String res = "-23876";
        int resScale = -224;
Stop searching for code, let great code find you!  Add Codota to your java IDE