JavaScript | Math.log10()方法 (JavaScript | Math.log10() Method)
Math operations in JavaScript are handled using functions of math library in JavaScript. In this tutorial on Math.log10() method, we will learn about the log10() method and its working with examples.
JavaScript中的数学运算是使用JavaScript中的数学库函数处理的。 在有关Math.log10()方法的本教程中,我们将学习log10()方法及其示例。
Math.log10() is a function in math library of JavaScript that is used to support math's operation of finding logarithm with base 10 of a number.
Math.log10()是JavaScript数学库中的一个函数,用于支持数学以10为底的对数查找运算。
Syntax:
句法:
Math.log10(n);
Parameter(s):
参数:
n – It takes only one value which is the number whose logarithm 10 (log10) is to be found.
n –仅采用一个值,该值是要找到其对数10(log 10 )的数字。
Return value:
返回值:
The return type of this method is number, it returns the log10 of the given number.
此方法的返回类型为number ,它返回给定数字的log 10 。
Example 1: Finding the log10 of number
示例1:查找数字的对数10
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>
<script>
document.write(Math.log10(3) + "<br>");
document.write(Math.log10(87) + "<br>");
document.write(Math.log10(100) + "<br>");
document.write(Math.log10(512));
</script>
</body>
</html>
Output
输出量
Example 2: finding log of a string.
示例2:查找字符串的日志。
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>
<script>
document.write(Math.log10("Include help"));
</script>
</body>
</html>
Output
输出量
When a string is passed to the log10() method. It returns NaN denoting the passed value is not a number.
将字符串传递给log 10 ()方法时 。 它返回NaN表示传递的值不是数字。
Example 3: Find the log of a complex number.
示例3:查找复数的日志。
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>
<script>
document.write(Math.log10(1 + 2 i));
</script>
</body>
</html>
Output
输出量
Invalid or unexpected token
翻译自: https://www.includehelp.com/code-snippets/math-log10-method-with-example-in-javascript.aspx