O'Reilly logo

Java™ Phrasebook by Timothy Fisher

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Calculating a Logarithm

double logValue = Math.log(125.5);

In this phrase, we use the log() method of the java.lang.Math class to calculate the logarithm of the parameter passed in. We pass in a value of double type, and the return value is also a double value. The log() method calculates the natural logarithm, using base e, where e is the standard value of 2.71828.

JDK1.5 added a new method to the Math class for directly calculating a base 10 logarithm. This is the log10() method. Similar to the log() method, this method takes a double input parameter, and returns a double result type. We can use this method to easily calculate a base 10 logarithm as follows:

double logBase10 = Math.log10(200);

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required