
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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
- Related Questions & Answers
- Create a BigDecimal via string in Java
- Create BigInteger via long type variable in Java
- Working with BigDecimal values in Java
- Java Program to create Big Decimal Values via a string
- Create BigInteger via string in Java
- Multiply one BigDecimal to another BigDecimal in Java
- Subtract one BigDecimal from another BigDecimal in Java
- Java Program to create a BigDecimal from a string type value
- Negate a BigDecimal value in Java
- Java Program to divide one BigDecimal from another BigDecimal
- Truncate BigDecimal value in Java
- Temporary Values via local() in Perl
- Math operations for BigDecimal in Java
- Assigning long values carefully in java to avoid overflow
- Compare BigDecimal movePointRight and scaleByPowerOfTen in Java
Advertisements