Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Exponentiation calculations 1

Status
Not open for further replies.

Jetter88

Programmer
Nov 14, 2003
35
CA
hi...
I'm having a problem figuring out a calculation in Java. It works in Excel though.
Excel formula sample is:
Cell A7 = .065
(1+A7)^(1/12)-1
result=0.005261

How do I correctly get the ^ in Java?

thanks in advance.
Mark

 
As I answered you, Math.pow will suit your needs.

Cheers,
Dian
 
Do you know the exact statement I should use? I'm trying that as I did before... but can't get the same answer?
 
Oh, the .0 trick

Code:
double A7 = .065;
double result= Math.pow((1+A7),(1.0/12.0))-1;  
System.out.println(result);

Cheers,
Dian
 
AWESOME!!

Thank you very much for the quick response and answer!!


Mark
 
You're welcome.

Btw, the reason behind is that, if you don't add the .0, Java uses the integer division ie, takes the integer part of the division. In that case, 1/12=0

Cheers,
Dian
 
That is exactly what was happening while i was debugging and then I though "double" couldn't handle it. So I was think Float, but give up on that too.

That was a piece of the calculation... if I run into a snag... I will post again... Thanks for yuor help!


Mark
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top