目录

RoundingMode getRoundingMode()

描述 (Description)

java.math.MathContext.getRoundingMode()返回roundingMode设置。

这将是RoundingMode.CEILING,RoundingMode.DOWN,RoundingMode.FLOOR,RoundingMode.HALF_DOWN,RoundingMode.HALF_EVEN,RoundingMode.HALF_UP,RoundingMode.UNNECESSARY或RoundingMode.UP之一。

声明 (Declaration)

以下是java.math.MathContext.getRoundingMode()方法的声明。

public RoundingMode getRoundingMode()

参数 (Parameters)

NA

返回值 (Return Value)

此方法返回RoundingMode对象,该对象是roundingMode设置的值。

异常 (Exception)

NA

例子 (Example)

以下示例显示了math.MathContext.getRoundingMode()方法的用法。

package com.iowiki;
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
↑回到顶部↑
WIKI教程 @2018