Warning: include_once(): http:// wrapper is disabled in the server configuration by allow_url_include=0 in /home/users/2/moriya-h5/web/confrage/java/bigdecimal/comp_bigdecimal/comp_bigdecimal.html on line 2

Warning: include_once(http://www.confrage.com/bin/header.php): failed to open stream: no suitable wrapper could be found in /home/users/2/moriya-h5/web/confrage/java/bigdecimal/comp_bigdecimal/comp_bigdecimal.html on line 2

Warning: include_once(): Failed opening 'http://www.confrage.com/bin/header.php' for inclusion (include_path='.:/usr/local/php/5.6/lib/php') in /home/users/2/moriya-h5/web/confrage/java/bigdecimal/comp_bigdecimal/comp_bigdecimal.html on line 2
BigDecimalで0と0.00の比較 | Java | 株式会社CONFRAGE
Warning: include_once(/home/sites/heteml/users/m/o/r/moriya-h5/web/confrage/bin/menu.php): failed to open stream: No such file or directory in /home/users/2/moriya-h5/web/confrage/java/bigdecimal/comp_bigdecimal/comp_bigdecimal.html on line 17

Warning: include_once(): Failed opening '/home/sites/heteml/users/m/o/r/moriya-h5/web/confrage/bin/menu.php' for inclusion (include_path='.:/usr/local/php/5.6/lib/php') in /home/users/2/moriya-h5/web/confrage/java/bigdecimal/comp_bigdecimal/comp_bigdecimal.html on line 17
BigDecimalで0と0.00の比較
0と0.00のような少数ありと少数なしの数値の比較をしたい場合、BigDecimalのcompareToメソッドを使用します。
この少数の桁数が異なることを「スケールが異なる」と言います。

import java.math.BigDecimal;

public class Test{
    public static void main(String[] args){
        BigDecimal bg1 = new BigDecimal(0);
        BigDecimal bg2 = new BigDecimal(0.00);
 
        if(bg1.compareTo(bg2) == 0){
            System.out.println("bg1とbg2は等しいです:bg1="+bg1+":bg2="+bg2);
        }else{
            System.out.println("bg1とbg2は等しくないです:bg1="+bg1+":bg2="+bg2);
        }
    }
}
実行結果は以下のようになります。

bg1とbg2は等しいです:bg1=0:bg2=0.00

Back to top

Information

Warning: include_once(/home/sites/heteml/users/m/o/r/moriya-h5/web/confrage/bin/side_bar.php): failed to open stream: No such file or directory in /home/users/2/moriya-h5/web/confrage/java/bigdecimal/comp_bigdecimal/comp_bigdecimal.html on line 76

Warning: include_once(): Failed opening '/home/sites/heteml/users/m/o/r/moriya-h5/web/confrage/bin/side_bar.php' for inclusion (include_path='.:/usr/local/php/5.6/lib/php') in /home/users/2/moriya-h5/web/confrage/java/bigdecimal/comp_bigdecimal/comp_bigdecimal.html on line 76

Warning: include_once(/home/sites/heteml/users/m/o/r/moriya-h5/web/confrage/bin/seo.php): failed to open stream: No such file or directory in /home/users/2/moriya-h5/web/confrage/java/bigdecimal/comp_bigdecimal/comp_bigdecimal.html on line 85

Warning: include_once(): Failed opening '/home/sites/heteml/users/m/o/r/moriya-h5/web/confrage/bin/seo.php' for inclusion (include_path='.:/usr/local/php/5.6/lib/php') in /home/users/2/moriya-h5/web/confrage/java/bigdecimal/comp_bigdecimal/comp_bigdecimal.html on line 85