- Home
·
- Math/Dates
·
- Ever wanted a computer to format numbers based on Significant Digits? Here's a function to do it
Ever wanted a computer to format numbers based on Significant Digits? Here's a function to do it
Ever wanted a computer to format numbers based on Significant Digits? Here's a function to do it
Rate Ever wanted a computer to format numbers based on Significant Digits? Here's a function to do it
(2(2 Vote))
ByVal intDigits As Integer) As Double
Dim dFactor As Double
Dim dStart As Double
Dim Bneg As Boolean
Dim msg As String
Dim mg As Integer
On Error GoTo ER:
If num = 0 Then
Sig_Digits = 0
Exit Function
End If
If num < 0 Then
dStart = num * -1
Bneg = True
Else
dStart = num
End If
dFactor = 1E+99
Do Until dFactor = 1E-99
If dStart >= dFactor / 10 And dStart < dFactor Then
dStart = dStart / dFactor
dStart = Round(dStart, intDigits)
dStart = dStart * dFactor
If Bneg = True Then dStart = dStart * -1
Exit Do
End If
dFactor = dFactor / 10
Loop
Sig_Digits = dFactor
Exit Function
ER:
msg = "Significant Digits Function Error"
mg = MsgBox(msg, vbExclamation, App.Title)
Sig_Digits = 0
Exit Function
End Function
Ever wanted a computer to format numbers based on Significant Digits? Here's a function to do it Comments
No comments yet — be the first to post one!
Post a Comment