The Math.log10() method returns the base-10 logarithm of a number.


  • If a is a positive number, the return value is a double.
  • If a is NaN or a negative number, the return value is NaN.
  • If a is positive infinity, the return value is positive infinity.
  • If a is negative or positive zero, the return value is negative infinity.
  • If a is 10n for integer n, the return value is n.


The following example demonstrates using the .log10() method to find base-10 logarithms:

// Main.java
public class Main {
public static void main(String args[]) {
double a = 10;
double b = -6;
double c = 0;
double d = -0;
System.out.println("The result of log10(" + a + ") is: " + Math.log10(a));
System.out.println("The result of log10(" + b + ") is: " + Math.log10(b));
System.out.println("The result of log10(" + c + ") is: " + Math.log10(c));
System.out.println("The result of log10(" + d + ") is: " + Math.log10(d));

This will produce the following output:

The result of log10(10.0) is: 1
The result of log10(-6.0) is: NaN
The result of log10(0.0) is: -Infinity
The result of log10(0.0) is: -Infinity


Interested in helping build Docs? Read the Contribution Guide or share your thoughts in this feedback form.

Learn Java on Codecademy