aspose file tools*
The moose likes Java in General and the fly likes Power of a number ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Power of a number ?" Watch "Power of a number ?" New topic
Author

Power of a number ?

Abhinav Yadav
Ranch Hand

Joined: Nov 08, 2009
Posts: 34
how can we directly find the power of a number in java ,as in C language there is a function math.pow() is any such type of function provided by java?


No Dream Too Big
Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

Eh Math.pow() maybe.


"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
Ireneusz Kordal
Ranch Hand

Joined: Jun 21, 2008
Posts: 423
Java has also Math.pow function:
http://download-llnw.oracle.com/javase/6/docs/api/java/lang/Math.html#pow%28double,%20double%29
Abhinav Yadav
Ranch Hand

Joined: Nov 08, 2009
Posts: 34
Wouter Oet wrote:Eh Math.pow() maybe.

thanks
it worked
but what should i do to make all the numbers to be printed and not the exponential part
eg if i did

what should be done to print the exact no. i.e
548815620517731830194541.899025343415715973535967221869852721
Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

Why don't you try to search for it? Because one maybe a couple searches and you'll find the answer.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38351
    
  23
Wouter Oet wrote:Why don't you try to search for it? Because one maybe a couple searches and you'll find the answer.
Hint: The double you are using is a "primitive type". If you find the Java™ Tutorials, there is a section about primitive types and it gives a hint for exactly what you want there.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19670
    
  18

abhinav yadav wrote:but what should i do to make all the numbers to be printed and not the exponential part
eg if i did

what should be done to print the exact no. i.e
548815620517731830194541.899025343415715973535967221869852721

Switch to BigDecimal. That's the only class in the core API that fully preserves full precision.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Power of a number ?