|
-
May 5th, 2000, 04:44 AM
#1
Thread Starter
Member
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 
-
May 5th, 2000, 05:01 AM
#2
Addicted Member
Is this supposed to round?
-
May 5th, 2000, 05:12 AM
#3
Addicted Member
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
-
May 5th, 2000, 05:39 AM
#4
Hyperactive Member
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.
-
May 5th, 2000, 11:19 PM
#5
Thread Starter
Member
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|