Java-math-mathcontext-getroundingmode
提供:Dev Guides
Java.math.MathContext.getRoundingMode()メソッド
説明
- java.math.MathContext.getRoundingMode()*はroundingMode設定を返します。
これは、RoundingMode.CEILING、RoundingMode.DOWN、RoundingMode.FLOOR、RoundingMode.HALF_DOWN、RoundingMode.HALF_EVEN、RoundingMode.HALF_UP、RoundingMode.UNNECESSARY、またはRoundingMode.UPのいずれかになります。
宣言
以下は* java.math.MathContext.getRoundingMode()*メソッドの宣言です。
public RoundingMode getRoundingMode()
パラメーター
NA
戻り値
このメソッドは、roundingMode設定の値であるRoundingModeオブジェクトを返します。
例外
NA
例
次の例は、math.MathContext.getRoundingMode()メソッドの使用法を示しています。
package com.finddevguides;
import java.math.*;
public class MathContextDemo {
public static void main(String[] args) {
//create 2 MathContext objects
MathContext mc1, mc2;
//assign context settings to mc1, mc2
mc1 = new MathContext(4);
mc2 = new MathContext(50, RoundingMode.CEILING);
//create 2 RoundingMode objects
RoundingMode rm1, rm2;
//assign roundingmode of mc1, mc2 to rm1, rm2
rm1 = mc1.getRoundingMode();
rm2 = mc2.getRoundingMode();
String str1 = "Rounding Mode of mc1 is " + rm1;
String str2 = "Rounding Mode of mc2 is " + rm2;
//print rm1, rm2 values
System.out.println( str1 );
System.out.println( str2 );
}
}
上記のプログラムをコンパイルして実行すると、次の結果が生成されます-
Rounding Mode of mc1 is HALF_UP
Rounding Mode of mc2 is CEILING