Java-math-bigdecimal-plus

提供:Dev Guides
移動先:案内検索

Java.math.BigDecimal.plus()メソッド

説明

  • java.math.BigDecimal.plus()*は、値が(+ this)でスケールがthis.scale()であるBigDecimalを返します。

このBigDecimalを単純に返すこのメソッドは、単項マイナスメソッドnegate()との対称性のために含まれています。

宣言

以下は* java.math.BigDecimal.plus()*メソッドの宣言です。

public BigDecimal plus()

パラメーター

NA

戻り値

このメソッドは、オブジェクト値、つまりthisを返します。

例外

NA

次の例は、math.BigDecimal.plus()メソッドの使用法を示しています。

package com.finddevguides;

import java.math.*;

public class BigDecimalDemo {

   public static void main(String[] args) {

     //create 2 BigDecimal Objects
      BigDecimal bg1, bg2;

     //assign value to bg1
      bg1 = new BigDecimal("-123.126");

     //assign the result of plus method on bg1 to bg2
      bg2 = bg1.plus();

      String str = "The value of the BigDecimal is " + bg2;

     //print the value of bg2
      System.out.println( str );
   }
}

上記のプログラムをコンパイルして実行すると、次の結果が生成されます-

The value of the BigDecimal is -123.126