【java】Java.math.BigDecimal.subtract()方法实例
java.math.BigDecimal.subtract(BigDecimal subtrahend) 返回一个BigDecimal,其值为 (this - subtrahend), 精度为 max(this.scale(), subtrahend.scale()).
声明
以下是声明java.math.BigDecimal.subtract()方法
public BigDecimal subtract(BigDecimal subtrahend)
参数:
subtrahend - 此BigDecimal要减去的值
返回值
此方法返回BigDecimal对象的值减去与减数后的值,即 - subtrahend
异常
NA
例子
下面的例子显示math.BigDecimal.subtract()方法的用法:
import java.math.*; public class BigDecimalDemo { public static void main(String[] args) { // create 3 BigDecimal objects
BigDecimal bg1, bg2, bg3; bg1 = new BigDecimal("100.123");
bg2 = new BigDecimal("50.56"); // subtract bg1 with bg2 and assign result to bg3
bg3 = bg1.subtract(bg2); String str = "The Result of Subtraction is " + bg3; // print bg3 value
System.out.println( str );
}
}
让我们编译和运行上面的程序,这将产生以下结果:
The Result of Subtraction is 49.563
转自:https://blog.csdn.net/captian_900331/article/details/51272953 有改动
【java】Java.math.BigDecimal.subtract()方法实例的更多相关文章
- Java.math.BigDecimal.abs()方法
java.math.BigDecimal.abs()返回一个BigDecimal,其值是此BigDecimal的绝对值,其标度是this.scale(). 声明 以下是java.math.BigDec ...
- (转)Java.lang.reflect.Method invoke方法 实例
背景:今天在项目中用到Method 的invoke方法,但是并不理解,查完才知道,原来如此! import java.lang.reflect.Method; /** * Java.lang.refl ...
- 解决java.math.BigDecimal divide方法运算结果为无限小数问题
http://samueli.iteye.com/blog/224755 BigDecimal除法运算报错,错误如下:Non-terminating decimal expansion; no exa ...
- java.lang.Math类,方法学习笔记
/**java.lang 包中的Math 类提供有常量 * 并包含有用于执行基本数学运算的 * 方法,如初等指数.对数.平方根 * 用于进行更高级的数学运算.由于 * 在Math 类的方法都是静态的, ...
- Java Number & Math 类
// java.lang.Math 常用 // xxxValue() 方法用于将 Number 对象转换为 xxx 数据类型的值并返回. System.out.println(((Integer) 5 ...
- BigDecimal.divide方法
java.math.BigDecimal.divide(BigDecimal divisor, int roundingMode) 返回一个BigDecimal,其值为(this/除数),其标度是th ...
- java.math.BigDecimal保留两位小数,保留小数,精确位数
http://blog.csdn.net/yuhua3272004/article/details/3075436 使用java.math.BigDecimal工具类实现 java保留两位小数问题 ...
- java.math.BigDecimal类
BigDecimal类用于高精度计算.一般的float型和Double型数据只可以用来做科学计算或者是工程计算,由于在商业计算中,要求的数字精度比较高,所以要用到java.math.BigDecima ...
- java.math.BigDecimal类multiply的使用
java.math.BigInteger.multiply(BigInteger val) 返回一个BigInteger,其值是 (this * val).声明 以下是java.math.BigInt ...
随机推荐
- reduce方法的使用
reduce(收敛):接收一个回调函数作为累加器,数组中的每个值(从左到右)开始缩减,最终为一个值,是ES5中新增的又一个数组逐项处理方法. reduce(callback,initialValue) ...
- 定位之z-index
我们已经知道固定定位(fixed)和绝对定位(absolute)可以让盒子浮起来 相对定位(relactive)虽然不能让盒子浮起来,但也是可以让图层浮起来 那么既然大家都可以浮起来,就会存在一个问题 ...
- Linux Ubuntu XShell连接虚拟机问题记录
我们先用ip addr / ifconfig查看虚拟机ip地址,然后到windows下的cmd中ping 一下对应地址 一般是可以ping通的. 然后用Xshell或者其他工具连接虚拟机. 如果连不上 ...
- curl函数错误码对照信息表
- 【Zookeeper】应用场景概述
一.数据发布与订阅(配置中心) 二.负载均衡 三.命名服务(Naming Service) 四.分布式通知/协调 五.集群管理与Master选举 六.分布式锁 七.分布式事务 一.数据发布与订阅(配置 ...
- 05 Windows编程——Windows程序框架
源码 #include<Windows.h> LRESULT CALLBACK WindProc(HWND hwnd, UINT message, WPARAM wParam, LPARA ...
- 补充:HTML标签和CSS
角标标签: 上角标:sup 下角标:sub <!DOCTYPE html> <html> <head> <meta charset="UTF-8&q ...
- 深度解析Word2vec
Word2vec 本质上是一种降维操作--把词语从 one-hot encoder 形式的表示降维到 Word2vec 形式的表示,即Distributed Representation.也就是,通过 ...
- 操作系统-chapter1
课程:https://mooc.study.163.com/learn/1000002004?tid=2402971010&_trace_c_p_k2_=f79694c7fc04429bb9b ...
- 五、vue基础--生命周期函数
1.创建阶段: a.beforeCreate:Vue已经创建了,但是data,methods都还没有被创建好 b.created:datamethods都被创建好了 c.beforeMount:模板经 ...