I need a log function for JavaScript, but it needs to be base 10. I can’t see any listing for this, so I’m assuming it’s not possible. Are there any math wizards out there who know a solution for this?
I need a log function for JavaScript, but it needs to be base 10.
Share
“Change of Base” Formula / Identity
Since
Math.log(x)in JavaScript returns the natural logarithm ofx(same as ln(x)), for base 10 you can divide byMath.log(10)(same as ln(10)):Math.LN10is a built-in precomputed constant forMath.log(10), so this function is essentially identical to: