Java examples for java.math:BigDecimal Calculation
add two BigDecimal together
//package com.java2s; import java.math.BigDecimal; public class Main { public static void main(String[] argv) throws Exception { BigDecimal amount1 = new BigDecimal("1234"); BigDecimal amount2 = new BigDecimal("1234"); System.out.println(add(amount1, amount2)); }/*from w w w . j a v a 2 s. c o m*/ /** * ? * * @param amount1 * @param amount2 * @return */ public static BigDecimal add(BigDecimal amount1, BigDecimal amount2) { BigDecimal result = new BigDecimal("0.00"); if (amount1 != null) { result = result.add(amount1); } if (amount2 != null) { result = result.add(amount2); } return result; } }