Java Number Add add4Money(Double value1, Double value2)

Here you can find the source of add4Money(Double value1, Double value2)

Description

add Money

License

Open Source License

Declaration

public static double add4Money(Double value1, Double value2) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.math.BigDecimal;

public class Main {

    public static double add4Money(Double value1, Double value2) {
        return getScaleValue4Money(defaultValue(value1).doubleValue() + defaultValue(value2).doubleValue());
    }// ww w .  ja  v a  2  s  .co m

    public static double getScaleValue4Money(double value) {
        return getScaleValue(value, 2);
    }

    public static Integer defaultValue(Integer value) {
        return defaultValue(value, 0);
    }

    public static Integer defaultValue(Integer value, Integer defaultValue) {
        if (value == null)
            return defaultValue;
        else
            return value;
    }

    public static Long defaultValue(Long value) {
        return defaultValue(value, 0L);
    }

    public static Long defaultValue(Long value, Long defaultValue) {
        if (value == null)
            return defaultValue;
        else
            return value;
    }

    public static Double defaultValue(Double value) {
        return defaultValue(value, 0.0);
    }

    public static Double defaultValue(Double value, Double defaultValue) {
        if (value == null)
            return defaultValue;
        else
            return value;
    }

    public static double getScaleValue(double value, int sacle) {
        return getScaleValue(value, sacle, BigDecimal.ROUND_HALF_UP);
    }

    public static double getScaleValue(double value, int sacle, int round) {
        BigDecimal db = new BigDecimal(value);
        db = db.setScale(sacle, round);
        return db.doubleValue();
    }
}

Related

  1. add(Object addend, Object augend)
  2. add(Object num1, Object num2)
  3. add(String number1, String number2)
  4. add(T a, T b)
  5. add1(Double v1, Double v2)
  6. addAmounts(final double num1, final double num2)
  7. addDoubles(Double value, Double addValue)
  8. addDoubles(String str1, String str2, int rounding)
  9. DoubleToInt(double d, double multiply, double add)