# Thread: How do I perform basic math with BigDecimals

1. Member Join Date
Sep 2010
Posts
42
Rep Power
0

## How do I perform basic math with BigDecimals

i need to multiply, subtract, divide, get 10 to the power of a BigDecimal and the absloute value.

this is a sample with error on bottom:
Java Code:
```import java.util.*;
import java.math.BigDecimal;

public class tentothezero{
public static void main(String[]  arguments){

BigDecimal Bigy1 = new BigDecimal(36);
BigDecimal Bigy2 = new BigDecimal(11);

Bigy2 = new BigDecimal.multiply(Bigy1,Bigy2);
System.out.println(Bigy2);

--------------------Configuration: <Default>--------------------
C:\Documents and Settings\Ryan\My Documents\tentothezero.java:10: cannot find symbol
symbol  : class multiply
location: class java.math.BigDecimal
Bigy2 = new BigDecimal.multiply(Bigy1,Bigy2);
^
1 error

Process completed.```  Reply With Quote

2. ## Again, the API will show you the way. If you look here: BigDecimal multiply method API entry

you will see this:

Java Code:
```multiply

public BigDecimal multiply(BigDecimal multiplicand)

Returns a BigDecimal whose value is (this × multiplicand), and whose scale is (this.scale() + multiplicand.scale()).

Parameters:
multiplicand - value to be multiplied by this BigDecimal.
Returns:
this * multiplicand```
In your attempt above, you're trying to call the method off of the class, and if you look at the method definition in the API, you'll notice that the method is not a static method unlike some other BigDecimal methods such as valueOf. This means that the method is not called off of the BigDecimal class, but off of a BigDecimal object.

You'll also notice that the method takes only one BigDecimal parameter, not two. So to call it correctly, call it on one BigDecimal object, say Bigy1, and pass the other BigDecimal object in as a parameter.

e.g.,
Java Code:
`Bigy2 = Bigy1.multiply(Bigy2);`
Also, you'll want to learn and use java naming conventions so that others (including us and your teachers) will understand your code better and quicker. Variables should begin with a lower-case letter and classes with an upper-case letter.

Best of luck and keep studying the API!  Reply With Quote

3. Member Join Date
Sep 2010
Posts
42
Rep Power
0

## Thank you ill try it real quick  Reply With Quote

4. Member Join Date
Sep 2010
Posts
42
Rep Power
0

## thank you it worked in the above program ill try it in my Major one now to see if it works thanks alot!  Reply With Quote

5. ## You're welcome.  Reply With Quote

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•