Here you can find the source of add4Money(Double value1, Double value2)
public static double add4Money(Double value1, Double value2)
//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(); } }