Results 1 to 5 of 5
- 09-26-2010, 03:50 AM #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.
-
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
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);
Best of luck and keep studying the API!
- 09-26-2010, 04:08 AM #3
Member
- Join Date
- Sep 2010
- Posts
- 42
- Rep Power
- 0
Thank you ill try it real quick
- 09-26-2010, 04:09 AM #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!
-
Similar Threads
-
Adding BigDecimals
By ShoeNinja in forum New To JavaReplies: 4Last Post: 03-14-2011, 12:19 PM -
My buttons all perform their action like 100 times
By 711groove in forum New To JavaReplies: 0Last Post: 12-13-2009, 10:49 AM -
Cannot perform a PING
By mnementh64 in forum NetworkingReplies: 1Last Post: 09-17-2009, 04:39 PM -
Perform one action at a time
By Melki in forum AWT / SwingReplies: 6Last Post: 12-08-2008, 07:29 AM -
How to perform some event to button click
By eva in forum AWT / SwingReplies: 2Last Post: 01-16-2008, 12:27 AM
Bookmarks