Library contents

Java Math.log10

In Java, Math.log10 returns the base-ten logarithm of a positive number. A result of 2 for 100 means that 10² = 100.

A simple example

Math.log10

  1. Start with 100
  2. Do this Find the base-10 logarithm
  3. Result 2
Ten squared is 100. The logarithm returns the exponent 2.
Main.java
class Main {
    public static void main(String[] args) throws Exception {
        System.out.println(Math.log10(100.0));
    }
}
Output
2.0

Syntax

Java syntax
Math.log10(ratio)
JDK 21 method signatures (1)
public static double log10(double a)
Run these examples in Java

Save one example at a time as Main.java. Use JDK 21.

java Main.java

Count orders of magnitude in a reading

A sensor report must compare readings that span very different scales. Express the measurements on a logarithmic scale so a multiplicative change has a manageable numerical description.

From the programdouble ratio = 1000.0
Result3.000
Main.java

class Main {
    public static void main(String[] args) throws Exception {
        double ratio = 1000.0;

        System.out.printf(java.util.Locale.ROOT, "%.3f%n", (double) (Math.log10(ratio)));
    }
}
Output
3.000

A sensor reading 1000 times its baseline is three orders of magnitude higher.

Advertisements

Compare light meter readings

A lab compares readings from a light meter over a wide range of intensities. Convert the readings to a logarithmic scale to see their separation in orders of magnitude.

From the programdouble ratio = 100.0
Result2.000
Main.java
class Main {
    public static void main(String[] args) throws Exception {
        double ratio = 100.0;

        System.out.printf(java.util.Locale.ROOT, "%.3f%n", (double) (Math.log10(ratio)));
    }
}
Output
2.000

A reading one hundred times its baseline is two powers of ten above it.

Mark a tenfold light change

A sensor reads ten times its reference intensity. The chart marks powers of ten on its vertical scale.

Given10
Worked result1.000

Using 10 gives 1.000 for this measurement.

What to watch for

A zero or negative ratio has no finite real base-ten logarithm.

Documentation for Math.log10