- Trending Categories
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 Big Decimal Values via a string
Let’s create BigDecimal value with a string
BigDecimal val1 = new BigDecimal("37578975.8768"); BigDecimal val2 = new BigDecimal("62567878.9768");
You can also set the above as −
String str1 = “37578975.8768”; BigDecimal val1 = new BigDecimal(str1); String str2 = “62567878.9768”; BigDecimal val2 = new BigDecimal(str2);
Now, you can also perform operations like −
val1 = val1.add(val2); System.out.println("Addition Operation = " + val1);
The following is an example −
Example
import java.math.BigDecimal; public class Demo { public static void main(String[] argv) throws Exception { // creating BigDecimal values via a string BigDecimal val1 = new BigDecimal("37578975.8768"); BigDecimal val2 = new BigDecimal("62567878.9768"); System.out.println("Value 1 : "+val1); System.out.println("Value 2 : "+val2); val1 = val1.add(val2); System.out.println("Addition Operation = " + val1); val1 = val1.multiply(val2); System.out.println("Multiplication Operation = " + val1); } }
Output
Value 1 : 37578975.8768 Value 2 : 62567878.9768 Addition Operation = 100146854.8536 Multiplication Operation = 6265976294387200.48179648
- Related Articles
- Create a BigDecimal via string in Java
- Create BigDecimal Values via a long in Java
- Create BigInteger via string in Java
- Set Decimal Place of a Big Decimal Value in Java
- Parse decimal string to create BigInteger in Java
- Java Program to create a boolean variable from string
- How to create a table with decimal values using JDBC?
- Java Program to Create String from Contents of a File
- Java Program to create Stream from a String/Byte Array
- Java Program to create a BigDecimal from a string type value
- Create BigInteger via long type variable in Java
- Java Program to save decimal
- Java Program to create Character Array from String Objects
- Java Program to create String to super class type mapping
- Python program to convert hex string to decimal

Advertisements