您的位置 首页 java

Java BigDecimal类型的 加减乘除运算和比较

加法:add 减法:subtract 乘法:multiply 除法:divide

BigDecimal bd1 = new BigDecimal(“15”);

BigDecimal bd2 = new BigDecimal(“20”);

BigDecimal bd3;

bd3 = bd1.add(bd2); // 加法

bd3 = bd1.subtract(bd2);// 减法

bd3 = bd1.multiply(bd2);// 乘法

bd3 = bd1.divide(bd2, 4, BigDecimal.ROUND_HALF_UP); // 除法 , 保留4位小数, 四舍五入 ; 不写后面两个参数当除不尽的时候会报错。

if(bd1.compareTo(bd2) == -1){

System.out.println(“bd1小于bd2”); // 0 等于 , 1 大于

}

if(bd1.compareTo(bd2) > -1){

System.out.println(“bd1大于等于bd2”); // < 1 小于等于

}

文章来源:智云一二三科技

文章标题:Java BigDecimal类型的 加减乘除运算和比较

文章地址:https://www.zhihuclub.com/172427.shtml

关于作者: 智云科技

热门文章

评论已关闭

6条评论

  1. Pelvic surgery can result in changes to the nerves and blood vessels responsible for erections

  2. Association of serum antioxidant capacity with coronary artery disease in middle aged men

  3. Most investigators now suggest that aggressive fluid administration is warranted early approximately the first 6 hours in septic patients, or in patients with other forms of shock, to restore circulation, whereas a more conservative approach is warranted later

  4. One side of the membrane is in contact with blood, and the other is in contact with air Interestingly, PINK1 and parkin were shown to repress mitochondrial antigen presentation delivered by mitochondrial derived vesicles, thus suppressing an immune response provoked by inflammation 107

网站地图