It's been about 13 years since I've heard anyone mention "sig figs,"
assuming your lingo is what I think it is. (Significant digits in
scientific math?)
Like, do you mean this?
3.45 * 1.2 = 4.1
as opposed to
3.45 * 1.2 = 4.14
If so, how do you intend to pass the arguments to the function? An array of
numbers used in an arithmetic operation and the result? Like, would you do:
Dim aNumbersUsed(1)
Dim dblResult
aNumbersUsed(0) = "3.45" '''pass as strings, not numerics
aNumbersUsed(1) = "1.2"
dblResult = 4.14 ''or the arithmetic operation here
Response.Write SigFig(aNumbers Used, dblResult)
Function SigFig(ArrayOfN umbers, Result)
Dim i, s
Dim iSigCount
Dim iMinSigs
Dim sResult, aResult, iInteger, iDecimal
iMinSigs = 99
For i = 0 To UBound(ArrayOfN umbers, 1)
s = ArrayOfNumbers( i)
If Int(s) = CDbl(s) Then ''no decimals
''cdbl to prevent leading zeros from counting,
''although I can't see why they'd be there. :]
iSigCount = Len(CStr(CDbl(s )))
Else ''decimal number
''get length before and after decimal
iSigCount = Len(CStr(Int(s) )) + Len(CStr(Split( s, ".")(1)))
End If
''If the sigcount is lower than what it was
''the last time through the loop, take that as
''the current number of significant digits to return
If iSigCount < iMinSigs Then iMinSigs = iSigCount
Next
''Now we presumably have the correct number of significant digits, so
''we can take the result and signify it
''I do not remember all the specific rules
''of significant digits.
''I imagine that step two will involve
''splitting the result that was passed by a the . character
''and testing LENs and padding with zeros or rounding
''For now, I'll just return the number of significant digits
If iMinSigs = 99 Then
''no significant digits found
SigFig = "There was no significance in what you passed to this
function."
Exit Function
Else
SigFig = iMinSigs
End If
End Function
Ray at work
"Mike D" <Mi***@discussi ons.microsoft.c om> wrote in message
news:83******** *************** ***********@mic rosoft.com...
I need a function that can format a number with the appropriate number of
sig figs. Ideallty a function that takes two values the value to be converted
and the number of sig figs I want it formatted to. Has anyone done this?
Any leads on how to? I have been searching the net and haven't found
anything yet.
Thanks
Mike