How can I specify the base for Math.log() in JavaScript?
问题 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? 回答1: "Change of Base" Formula / Identity The numerical value for logarithm to the base 10 can be calculated with the following identity. Since Math.log(x) in JavaScript returns the natural logarithm of x (same as ln(x) ), for base 10 you can divide by Math.log(10) (same as ln(10) ): function