In this section, you will learn how to add two big numbers. For adding two numbers implement two big decimal numbers then apply the Sum() method that takes both numbers. Now, you will have to define it and use the add() method to add both numbers. Finally, the result will be displayed on the command prompt (DOS prompt).
BigDecimal():
This is the constructor of BigDecimal class. It translates the data
into BigDecimal.
BigDecimal.add(BigDecimal big):
This method is used to add the two BigDecimal numbers.
Here is the code of program:
import java.math.BigDecimal;
|
Output of program:
| C:\vinod\Math_package>javac AddTwoBigNumbers.java C:\vinod\Math_package>java AddTwoBigNumbers Sum of two BigDecimal numbers: 150.002849999999995134203345514833927154 |
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.
Ask Questions? Discuss: Add two big numbers View All Comments
Post your Comment