-
Does anyone know how to calculate significant figures?
I am trying to write a routine that would return a varible set to the number of significant figures you ask for.
e.g.
call SigFig(1245.44, 3)
would return 1240
and SigFig(1245.44, 2)
would return 1200
e.t.c.
Any help is most appreciated :)
-
Is this supposed to round?
-
Well, I made it round anyways:
Code:
Public Function SigFig(num As Integer, NumOfPlaces As Integer) As Integer
Dim NewNum As String
NewNum = Mid$(Trim(Str(num)), 1, NumOfPlaces)
If Val(Mid$(num, NumOfPlaces + 1, 1)) >= 5 Then NewNum = NewNum + 1
While Len(Trim(Str(NewNum))) <> Len(Trim(Str(num)))
NewNum = NewNum * 10
Wend
SigFig = NewNum
End Function
-
Looks like a long way to me.
I would go with:
Public Function SigFig(num As long, NumOfPlaces As Integer) As long
SigNum= Cint(n/(10^NumOfPlaces))* 10^NumOfPlaces
end function
Realy I would not even make function of it.
-
thanks for your help guys Raydr's example does exactly what I need.
LG -- I am using a function because it will need to be called many times to produce columns of values for a financial program.