使用VBA和Excel函数的对数是不同的 [英] Logarithm is different using VBA and Excel function
问题描述
我正在尝试获取一个数字的日志,但看起来 Worksheet 函数给出了一个答案,而 VBA 给出了另一个答案.
I'm trying to get the log of a number but it looks like the Worksheet function gives one answer, and VBA another.
在VB中,使用Log(Range("A2"))
,其中A2为7,我得到1.94591014905531
,这是正确答案.但是,如果在工作表中,我使用 =Log(A2,10)
或 =Log10(a2)
,我会得到 0.84509804
.这是怎么回事?
In VB, using Log(Range("A2"))
where A2 is 7, I get 1.94591014905531
, which is the correct answer. But, if in the worksheet, I use =Log(A2,10)
or =Log10(a2)
, I get 0.84509804
. What's going on here?
推荐答案
VBA 的 Log
函数是自然对数.如果您想要以十为底的对数,则必须使用对数恒等式来转换基数.像这样:Log(x)/Log(10)
.
VBA's Log
function is the natural log. If you want log base ten you will have to use the logarithmic identity for converting bases. Like so: Log(x)/Log(10)
.
这篇关于使用VBA和Excel函数的对数是不同的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!