Using log base 10 in a formula in Java

CodyBugstein picture CodyBugstein · Dec 4, 2012 · Viewed 78.3k times · Source

I'm trying to write a Java program that can take values and put them into a formula involving log base 10.

How can I calculate log10 in Java?

Answer

Mysticial picture Mysticial · Dec 4, 2012

It looks like Java actually has a log10 function:

Math.log10(x)

Otherwise, just use math:

Math.log(x) / Math.log(10)

http://docs.oracle.com/javase/7/docs/api/java/lang/Math.html