divide Balance Money - Java java.math

Java examples for java.math:BigDecimal Calculation

Description

divide 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(divideBalance(balance,money,v));
    }/*from   www  .ja va2s.c  o  m*/
    
    public static float divideBalance(float balance, float money, int v) {
        if (balance != 0 && balance >= money) {
            return new BigDecimal(balance).divide(new BigDecimal(money))
                    .setScale(v, BigDecimal.ROUND_HALF_UP).floatValue();
        }
        return 0;
    }
}

Related Tutorials