- Java.math package classes
- Java.math - Home
- Java.math - BigDecimal
- Java.math - BigInteger
- Java.math - MathContext
- Java.math package extras
- Java.math - Enumerations
- Java.math - Discussion
Java.math.BigInteger.toString() Method
Description
The java.math.BigInteger.toString() returns the decimal String representation of this BigInteger. The digit-to-character mapping provided by Character.forDigit is used, and a minus sign is prepended if appropriate.
This representation is compatible with the (String) constructor, and allows for String concatenation with Java's + operator.
Declaration
Following is the declaration for java.math.BigInteger.toString() method.
public String toString()
Overrides
toString in class Object.
Parameters
NA
Return Value
This method returns the decimal String representation of this BigInteger.
Exception
NA
Example
The following example shows the usage of math.BigInteger.toString() method.
package com.tutorialspoint; 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 ); } }
Let us compile and run the above program, this will produce the following result −
String value of 1234 is 1234 String value of -1234 is -1234
java_math_biginteger.htm
Advertisements