Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,943 questions

51,884 answers

573 users

How to calculate log10 (base-10 logarithm) in JavaScript

2 Answers

0 votes
<!DOCTYPE html>
<html>
<head>  
</head>
 
<body>
<p id="calc"></p>
<script>
function _log10(n) 
{
    document.getElementById("calc").innerHTML =  Math.log(n) / Math.LN10;
    //document.getElementById("calc").innerHTML =  Math.log(n) / Math.log(10);
}
</script>
<input type="button" value="log10(123)" onclick="_log10(123)" />
<input type="button" value="log10(1234)" onclick="_log10(1234)" />
<input type="button" value="log10(12345)" onclick="_log10(12345)" />

 
</body>
</html>
<!-- 
run:

2.0899051114393976
3.091315159697223
4.091491094267951
-->

 



answered Dec 15, 2015 by avibootz
edited Dec 15, 2015 by avibootz
0 votes
<!DOCTYPE html>
<html>
<head>  
</head>
  
<body>
<p id="calc"></p>
<script>
function _log10(n) 
{
    document.getElementById("calc").innerHTML =  parseInt(Math.log(n) / Math.LN10);
    //document.getElementById("calc").innerHTML =  parseInt(Math.log(n) / Math.log(10));
}
</script>
<input type="button" value="log10(123)" onclick="_log10(123)" />
<input type="button" value="log10(1234)" onclick="_log10(1234)" />
<input type="button" value="log10(12345)" onclick="_log10(12345)" />
 
  
</body>
</html>

<!-- 
run:

2
3
4
-->

 



answered Dec 15, 2015 by avibootz
edited Dec 15, 2015 by avibootz

Related questions

3 answers 333 views
1 answer 275 views
1 answer 134 views
...