java.math.MathContext.toString()%uA0返回MathContext的字符串表示形式。
返回的字符串表示MathContext对象为两个空格分开的单词(由单个空格字符,&apos u0020&apos分隔,且没有前导或尾随空白)的设置,如下所示:
-
字符串“precision=”,后面紧跟的精度设置的值作为数字字符串,由Integer.toString方法生成。
-
字符串“RoundingMode=”,后面紧跟着的RoundingMode设置作为一个字的值。这个字将是相同的,为相应的公用常数与RoundingMode枚举的名称。
附加可能会被附加到的toString未来的结果,如果更多的属性添加到这个类。
声明
以下是java.math.MathContext.toString()方法的声明
public String toString()
覆盖
Object类中的toString
参数
-
NA
返回值
此方法返回表示上下文设置一个String。
异常
-
NA
例子
下面的例子显示math.MathContext.toString()方法的用法
package com.yiibai 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(6, RoundingMode.DOWN) mc2 = new MathContext(20, RoundingMode.FLOOR) // create 2 String objects String s1, s2 // assign string representation of mc1, mc2 to s1, s2 s1 = mc1.toString() s2 = mc2.toString() String str1 = "String representation of mc1 is " + s1 String str2 = "String representation of mc2 is " + s2 // print s1, s2 values System.out.println( str1 ) System.out.println( str2 ) } }
让我们编译和运行上面的程序,这将产生以下结果:
String representation of mc1 is precision=6 roundingMode=DOWN String representation of mc2 is precision=20 roundingMode=FLOOR