multiply Balance Money - Java java.math

Java examples for java.math:BigDecimal Calculation

Description

multiply Balance Money

Demo Code


import java.math.BigDecimal;
import java.security.MessageDigest;
import org.apache.log4j.Logger;

public class Main{
    public static void main(String[] argv) throws Exception{
        float balance = 2.45678f;
        float money = 2.45678f;
        int v = 2;
        System.out.println(multiplyBalance(balance,money,v));
    }//from w  ww.j  a va 2s .  c o m
    
    public static float multiplyBalance(float balance, float money, int v) {
        if (balance != 0 && balance >= money) {
            return new BigDecimal(balance).multiply(new BigDecimal(money))
                    .setScale(v, BigDecimal.ROUND_HALF_UP).floatValue();
        }
        return 0;
    }
}

Related Tutorials