Java Program to create a BigDecimal from a string type value


Let us first create a BigDecimal type with string value −

BigDecimal one = new BigDecimal("562537627.8787867");

Now, create a BigDecimal with long −

BigDecimal two = BigDecimal.valueOf(562L);

After that use add() with the aug end value i.e. the value in “two” object −

one = one.add(two);

Example

 Live Demo

import java.math.BigDecimal;
public class Demo {
   public static void main(String[] argv) throws Exception {
      BigDecimal one = new BigDecimal("562537627.8787867");
      BigDecimal two = BigDecimal.valueOf(562L);
      one = one.add(two);
      System.out.println(one);
   }
}

Output

562538189.8787867

Updated on: 30-Jul-2019

260 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements