Logarithm is different using VBA and Excel function

后端 未结 2 739
轻奢々
轻奢々 2020-12-06 20:05

I\'m trying to get the log of a number but it looks like the Worksheet function gives one answer, and VBA another.

In VB, using Log(Range(\"A2\")) where

相关标签:
2条回答
  • 2020-12-06 20:23

    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).

    0 讨论(0)
  • 2020-12-06 20:31
    Function roundit1(nn As Variant, sd As Variant)
        nn = Val(nn)
        If Not (nn = 0) Then
            xx = (1 + Int(Log(Abs(nn)) / Log(10)))
        Else
            xx = 0
        End If
        ' significant digits
        roundit = sd - xx
        If roundit < 0 Then roundit = 0
       roundit1 = Round(nn, roundit)
    End Function
    
    0 讨论(0)
提交回复
热议问题