当前位置:   article > 正文

java double和BigDecimal类型的加减乘除工具类_java double和bigdecimal 相乘

java double和bigdecimal 相乘

我不写代码,我只是代码的搬运工。

double和BigDecimal类型的加减乘除工具类


public class CalculateUtil {

	/**
	 * 数据处理除法
	 * 
	 * @return
	 */
	public static Double doubleDiv(Double one, Integer two) {
		Double res = one / two;
		return (double) Math.floor(res * 100) / 100;

	}

	/**
	 * 数据处理乘法
	 * 
	 * @return
	 */
	public static Double doubleMult(Double one, Integer two) {
		Double res = one * two;
		return (double) Math.floor(res * 100) / 100;

	}

	/**
	 * 数据处理-减法
	 * 
	 * @return
	 */
	public static Double doubleSub(Double one, Double two) {
		Double res = one - two;
		if (res < 0) {
			return 0.0;
		}
		return (double) Math.floor(res * 100) / 100;
	}

	/**
	 * 数据处理-加法
	 * 
	 * @return
	 */
	public static Double doubleAad(Double one, Double two) {
		Double res = one + two;
		return (double) Math.floor(res * 100) / 100;
	}

	/**
	 * double类型加密
	 * 
	 * @param param
	 * @return
	 */
	public static String doubleEncoder(Double param) {
		String ss = param.toString();
		String sss = ss.replace("0", "q").replace("1", "a").replace("2", "z").replace("3", "x").replace("4", "s")
				.replace("5", "w").replace("6", "e").replace("7", "d").replace("8", "c").replace("9", "v")
				.replace(".", "=");
		return sss;
	}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
/**
 * double类型解密
 * 
 * @param param
 * @return
 */
public static String doubleDecoder(String param) {
	return param.replace("q", "0").replace("a", "1").replace("z", "2").replace("x", "3").replace("s", "4")
			.replace("w", "5").replace("e", "6").replace("d", "7").replace("c", "8").replace("v", "9")
			.replace("=", ".");
}

/**
 * Integer 数据处理-减法
 * 
 * @param one
 * @param two
 * @return
 */
public static Integer integerSub(Integer one, Integer two) {
	Integer res = one - two;
	return res;
}

/**
 * 加法 BigDecimal
 * 
 * @param one
 * @param two
 * @return
 */
public static String BigAdd(String one, String two) {
	BigDecimal bignum1 = new BigDecimal(one);
	BigDecimal bignum2 = new BigDecimal(two);
	BigDecimal add = bignum1.add(bignum2);
	return add.toString();
}

/**
 * 减法 BigDecimal
 * 
 * @param one
 * @param two
 * @return
 */
public static String BigSub(String one, String two) {
	BigDecimal bignum1 = new BigDecimal(one);
	BigDecimal bignum2 = new BigDecimal(two);
	BigDecimal subtract = bignum1.subtract(bignum2);
	return subtract.toString();
}

/**
 * 乘法 BigDecimal
 * 
 * @param one
 * @param two
 * @return
 */
public static String BigMult(String one, String two) {
	BigDecimal bignum1 = new BigDecimal(one);
	BigDecimal bignum2 = new BigDecimal(two);
	BigDecimal multiply = bignum1.multiply(bignum2);
	multiply = new BigDecimal(multiply.toString());
	multiply = multiply.setScale(2, BigDecimal.ROUND_FLOOR);
	return multiply.toString();
}

/**
 * 除法 BigDecimal
 * 
 * @param one
 * @param two
 * @return
 */
public static String BigDiv(String one, String two) {
	BigDecimal bignum1 = new BigDecimal(one);
	BigDecimal bignum2 = new BigDecimal(two);
	BigDecimal divide = bignum1.divide(bignum2, 2, RoundingMode.HALF_UP);
	return divide.toString();
}

public static void main(String[] args) {
	String bigMult = CalculateUtil.BigDiv("12.401", "3");
	System.out.println(bigMult);
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/知新_RL/article/detail/319833?site
推荐阅读
相关标签
  

闽ICP备14008679号