Excel log equivilent to JS Math.log()

2019-09-07 20:20发布

In my javascript code I have the following

Math.log(20) = 2.995732273553991

In my excel formula I try to replicate this with

=LOG(20) = 1.301029996

Anyone have any idea why I'm getting two different outcomes? I'd like my excel to match my js.

2条回答
男人必须洒脱
2楼-- · 2019-09-07 20:54

Math.log(20) is base e, while LOG(20) is base 10.

You're not looking for LOG(20), but probably rather LN(20) (base e).

enter image description here

MDN (for javascript) : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/log

LN (for excel): https://support.office.com/en-us/article/LN-function-81fe1ed7-dac9-4acd-ba1d-07a142c6118f

The LOG Function you are using automatically set the second parameter to 10 if it is not set (default 10), as pointed out there:

enter image description here

From here: https://support.office.com/en-nz/article/LOG-function-4e82f196-1ca9-4747-8fb0-6c4a3abb3280

查看更多
Summer. ? 凉城
3楼-- · 2019-09-07 20:55

Just in case anyone is interested in going the other direction: To get Excel's LOG(x) you can just do:

Math.log(x) / Math.log(10);

Or, being more efficient:

Math.log(x) / Math.LN10; 
查看更多
登录 后发表回答