- 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
Multiply one BigDecimal to another BigDecimal in Java
Use the multiply() method to multiply one BigDecimal to another in Java. This method returns a BigDecimal whose value is (this × multiplicand), and whose scale is (this.scale() + multiplicand.scale()).
The following is an example −
Example
import java.math.BigDecimal; public class Demo { public static void main(String[] argv) throws Exception { BigDecimal val1 = new BigDecimal("375789755.345778656"); BigDecimal val2 = new BigDecimal("525678755.155778656"); System.out.println("Value 1 = "+val1); System.out.println("Value 2 = "+val2); val2 = val2.multiply(val1); System.out.println("Result (Multiplication) = "+val2); } }
Output
Value 1 = 375789755.345778656 Value 2 = 525678755.155778656 Result (Multiplication) = 197544690790463541.417987494305166336
Let us see another example −
Example
import java.math.*; public class Demo { public static void main(String[] args) { BigDecimal bg1, bg2, bg3; bg1 = new BigDecimal("58.98"); bg2 = new BigDecimal("78.89"); bg3 = bg1.multiply(bg2); String str = "Multiplication = " +bg3; System.out.println( str ); } }
Output
Multiplication = 4652.9322
Advertisements