【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  有改動

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM