Calculates BigDecimal multiply i - Java java.math

Java examples for java.math:BigDecimal Calculation

Description

Calculates BigDecimal multiply i

Demo Code


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

public class Main {
    public static void main(String[] argv) throws Exception {
        BigDecimal num = new BigDecimal("1234");
        int i = 2;
        System.out.println(multiply(num, i));
    }//from  w  ww . j ava 2 s .  c o m

    /**
     * Calculates num multiply i
     * @param num the number
     * @param i the number
     * @return num multiply i
     */
    public static BigDecimal multiply(BigDecimal num, int i) {
        return num.multiply(new BigDecimal(i)).setScale(2,
                BigDecimal.ROUND_HALF_UP);
    }

    /**
     * Calculates i multiply num
     * @param i the number
     * @param num the number
     * @return i multiply num
     */
    public static BigDecimal multiply(int i, BigDecimal num) {
        return multiply(num, i);
    }
}

Related Tutorials