- Java.math 包附加内容
- Java.math - 枚举
- Java.math - 讨论
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 进行减法运算后,即 this - subtrahend。
异常
无
示例
以下示例演示了 math.BigDecimal.subtract() 方法的用法。
package com.tutorialspoint;
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
java_math_bigdecimal.htm
广告