Home Communities
IT Knowledge
Inspiration
Languages
EN

# Java - Math.log10() method example

0 points
Created by:
379

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

``````public class MathExample {

public static void main(String[] args) {
// Logarithm with base 10:
//                              x            y
System.out.println( Math.log10( 1    ) ); // 0.0
System.out.println( Math.log10( 3    ) ); // 0.47712125471966244
System.out.println( Math.log10( 10   ) ); // 1.0
System.out.println( Math.log10( 100  ) ); // 2.0
System.out.println( Math.log10( 1000 ) ); // 3.0

System.out.println( Math.log10( -1        ) ); //  NaN
System.out.println( Math.log10(  0        ) ); // -Infinity
System.out.println( Math.log10( Double.POSITIVE_INFINITY ) ); // +Infinity
}
}``````

The `Math.log10()` method is presented on the following chart:

## 1. Documentation

 Syntax ``````package java.lang; public final class Math { public static double log10(double x) { ... } }`````` Note: Classes in the `java.lang` package are imported automatically, so it is not necessary to do it manually - we use just `Math.log10()` call. Parameters `x` - double value in the range `0` to `+Infinity` (primitive value). Result `number` value calculated as log_10(x) mathematical function (primitive value). If `x` is negative it returns `NaN`. If `x` is equal to `0` it returns `-Infinity`. If `x` is equal to `+Infinity` it returns `-Infinity`. Description `log10` is a static method that takes one parameter and returns an approximation of the log_10(x) mathematical function (logarithm with base `10`). `log10` is called a common logarithm.

## References

1. Logarithm - Wikipedia

Join to our subscribers to be up to date with content, news and offers.