Parse decimal string to create BigInteger in Java

Java 8Object Oriented ProgrammingProgramming

To parse the decimal string to create BigInteger, just set the decimal string in the BigInteger.

Here is our BigInteger.

BigInteger one;
String decStr = "687879";
one = new BigInteger(decStr);

Let us see another example −

Example

 Live Demo

import java.math.*;
public class Demo {
   public static void main(String[] args) {
      BigInteger one, two;
      String decStr = "4373427";
      one = new BigInteger("250");
      two = new BigInteger(decStr);
      System.out.println("Result (BigInteger) : " +one);
      System.out.println("Result (Parsing Decimal String) : " +two);
   }
}

Output

Result (BigInteger) : 250
Result (Parsing Decimal String) : 4373427
raja
Updated on 29-Jun-2020 05:47:22

Advertisements