- 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
Create BigDecimal Values via a long in Java
Let us see how we can create BigDecimal values via a long. Here, we have set long values as a parameter to the BigDecimal constructor.
BigDecimal val1 = BigDecimal.valueOf(289L); BigDecimal val2 = BigDecimal.valueOf(299L);
We can also perform mathematical operations on it −
val2 = val2.subtract(val1);
The following is an example −
Example
import java.math.BigDecimal; public class Demo { public static void main(String[] argv) throws Exception { BigDecimal val1 = BigDecimal.valueOf(289L); BigDecimal val2 = BigDecimal.valueOf(299L); System.out.println("Value 1 : "+val1); System.out.println("Value 2 : "+val2); val2 = val2.subtract(val1); System.out.println("Result (Subtraction) = "+val2); } }
Output
Value 1 : 289 Value 2 : 299 Result (Subtraction) = 10
Advertisements
To Continue Learning Please Login
Login with Google