Parse Decimal String to Create BigInteger in Java



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
Updated on: 2020-06-29T05:47:22+05:30

268 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements