- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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
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
Advertisements
To Continue Learning Please Login
Login with Google