get Decimal Amount via BigDecimal - Java java.math

Java examples for java.math:BigDecimal

Description

get Decimal Amount via BigDecimal

Demo Code


//package com.java2s;
import java.math.BigDecimal;
import java.math.MathContext;
import java.math.RoundingMode;

public class Main {


    private static final int MC_PRECISION = 4;
    private static final int MC_SCALE = 2;

    public static BigDecimal getDecimalAmount(String parsedAmount) {
        return (new BigDecimal(parsedAmount, new MathContext(MC_PRECISION)))
                .setScale(MC_SCALE, RoundingMode.HALF_EVEN);
    }//ww w  .j a va2  s.c  om
}

Related Tutorials