Search code examples
javalogarithm

Using log base 10 in a formula in Java


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?


Solution

  • 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