parse To Big Decimal - Java java.math

Java examples for java.math:BigDecimal

Description

parse To Big Decimal

Demo Code


import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.DecimalFormat;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.log4j.Logger;

public class Main{
    public static void main(String[] argv) throws Exception{
        String amout = "java2s.com";
        System.out.println(parseToBigDecimal(amout));
    }/*from w w  w . j a v a 2 s.  c  om*/
    
    public static BigDecimal parseToBigDecimal(String amout) {
        if (amout == null)
            return null;
        return BigDecimal.valueOf(parseToDouble(amout));
    }
    
    public static Double parseToDouble(String amout) {
        if (amout == null)
            return null;
        String s = amout.replaceAll(",", "");
        return Double.valueOf(s);
    }
}

Related Tutorials