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  有改动

 

posted on 2019-08-07 14:24  我得去图书馆了  阅读(4962)  评论(0编辑  收藏  举报