Here you can find the source of addDoubles(String str1, String str2, int rounding)
Parameter | Description |
---|---|
str1 | a parameter |
str2 | a parameter |
rounding | a parameter |
public static String addDoubles(String str1, String str2, int rounding)
//package com.java2s; //License from project: Apache License import java.math.BigDecimal; public class Main { /**/*from w w w .j a v a 2s . c om*/ * add two double strings * @param str1 * @param str2 * @param rounding * @return */ public static String addDoubles(String str1, String str2, int rounding) { double d1 = toDouble(str1); double d2 = toDouble(str2); double rc = round(d1 + d2, rounding); return "" + rc; } /** * add two double strings and rounds to 2 decimals * @param str1 * @param str2 * @return */ public static String addDoubles(String str1, String str2) { return addDoubles(str1, str2, 2); } /** * toDouble */ public static double toDouble(String str) { double dval = 0.0; if (str == null || str.equalsIgnoreCase("null") || str.equalsIgnoreCase("") || str.equalsIgnoreCase("0")) return 0.00; // double dval = Double.parseDouble(str.trim()); return dval; } /** * round * * @param a * @param b * @return */ public static double round(double value, int decimalPlace) { BigDecimal bd = new BigDecimal(value); bd = bd.setScale(decimalPlace, BigDecimal.ROUND_HALF_UP); return bd.doubleValue(); } }