Java-math-biginteger-tostring
提供:Dev Guides
Java.math.BigInteger.toString()メソッド
説明
- java.math.BigInteger.toString()*は、このBigIntegerの10進文字列表現を返します。 Character.forDigitが提供する数字から文字へのマッピングが使用され、必要に応じてマイナス記号が付加されます。
この表現は(String)コンストラクターと互換性があり、Javaの+演算子とのString連結を可能にします。
宣言
以下は* java.math.BigInteger.toString()*メソッドの宣言です。
public String toString()
オーバーライド
クラス Object のtoString。
パラメーター
NA
戻り値
このメソッドは、このBigIntegerの10進文字列表現を返します。
例外
NA
例
次の例は、math.BigInteger.toString()メソッドの使用法を示しています。
package com.finddevguides;
import java.math.*;
public class BigIntegerDemo {
public static void main(String[] args) {
//create 2 BigInteger objects
BigInteger bi1, bi2;
//create 2 String objects
String s1, s2;
bi1 = new BigInteger("1234");
bi2 = new BigInteger("-1234");
//assign String value of bi1, bi2 to s1, s2
s1 = bi1.toString();
s2 = bi2.toString();
String str1 = "String value of " + bi1 + " is " +s1;
String str2 = "String value of " + bi2 + " is " +s2;
//print s1, s2 values
System.out.println( str1 );
System.out.println( str2 );
}
}
上記のプログラムをコンパイルして実行すると、次の結果が生成されます-
String value of 1234 is 1234
String value of -1234 is -1234