One - One Code All

Blog Content

Java.math.BigDecimal.subtract()方法实例

Java   2013-09-16 22:06:07

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

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 );
    }
}



上一篇:Apache服务httpd配置SSL证书以及HTTP重定向HTTPS
下一篇:使用numpy读取CSV文件数据loadtext

The minute you think of giving up, think of the reason why you held on so long.