Results 1 to 5 of 5

Thread: Significant Figures!!

  1. #1

    Thread Starter
    Member
    Join Date
    Sep 1999
    Location
    Gloucester, UK
    Posts
    33

    Question

    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

  2. #2
    Addicted Member
    Join Date
    Mar 2000
    Location
    Gainesville, FL
    Posts
    131
    Is this supposed to round?

  3. #3
    Addicted Member
    Join Date
    Mar 2000
    Location
    Gainesville, FL
    Posts
    131
    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

  4. #4
    Hyperactive Member
    Join Date
    Jun 1999
    Posts
    308
    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.

  5. #5

    Thread Starter
    Member
    Join Date
    Sep 1999
    Location
    Gloucester, UK
    Posts
    33

    Thumbs up

    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
  •  



Click Here to Expand Forum to Full Width