repost from scripting about sig fig functions

Discussion in 'ASP General' started by Mike D, Dec 17, 2004.

  1. Mike D

    Mike D Guest

    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
     
    Mike D, Dec 17, 2004
    #1
    1. Advertising

  2. Mike D wrote:
    > 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.
    >

    "sig figs"? Do you mean "significant figures"? In the true scientific sense
    of the word? Perhaps you should post some examples so we are all on the same
    page. Show some numbers and then show the output you want when passing
    different "sig fig" values.

    Bob Barrows
    --
    Microsoft MVP -- ASP/ASP.NET
    Please reply to the newsgroup. The email account listed in my From
    header is my spam trap, so I don't check it very often. You will get a
    quicker response by posting to the newsgroup.
     
    Bob Barrows [MVP], Dec 17, 2004
    #2
    1. Advertising

  3. 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(aNumbersUsed, dblResult)


    Function SigFig(ArrayOfNumbers, Result)
    Dim i, s
    Dim iSigCount
    Dim iMinSigs
    Dim sResult, aResult, iInteger, iDecimal

    iMinSigs = 99
    For i = 0 To UBound(ArrayOfNumbers, 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" <> wrote in message
    news:...
    > 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
    >
     
    Ray Costanzo [MVP], Dec 17, 2004
    #3
  4. Mike D

    Mike D Guest

    "Bob Barrows [MVP]" wrote:
    > >

    > "sig figs"? Do you mean "significant figures"? In the true scientific sense
    > of the word?


    Yes, all the things we hated about science.

    Example
    0.099 is 2 sig figs
    0.000009 is 1
    ..997 is 3

    I need to take a number like 0.0000099734 and convert to a wide variety of
    sig figs. Meaning some variables will need 2, some 3 etc. So I can't write
    it for only one level. I have since found
    http://www.vbforums.com/showthread.php?s=&threadid=269312

    and am testing it.

    Thanks for the replies




    Perhaps you should post some examples so we are all on the same
    > page. Show some numbers and then show the output you want when passing
    > different "sig fig" values.
    >
    > Bob Barrows
    > --
    > Microsoft MVP -- ASP/ASP.NET
    > Please reply to the newsgroup. The email account listed in my From
    > header is my spam trap, so I don't check it very often. You will get a
    > quicker response by posting to the newsgroup.
    >
    >
    >
     
    Mike D, Dec 17, 2004
    #4
  5. "Mike D" <> wrote in message
    news:...

    > Example
    > 0.099 is 2 sig figs
    > 0.000009 is 1


    I don't remember leading zeros to the right of the decimal not counting as
    significant. If that's that's one of the rules of significant digits, that
    doesn't make any sense to me. Why are those zeros any less significant than
    other numbers when in that position? No wonder I failed chemistry. ;]

    > .997 is 3


    That makes sense. But, .007 is just as precise a .997. Maybe I'll see if I
    can find a Physics textbook or something and read it.


    Ray at work
     
    Ray Costanzo [MVP], Dec 17, 2004
    #5
  6. Ray Costanzo [MVP] wrote:
    > "Mike D" <> wrote in message
    > news:...
    >
    >> Example
    >> 0.099 is 2 sig figs
    >> 0.000009 is 1

    >
    > I don't remember leading zeros to the right of the decimal not
    > counting as significant.


    Which explains my request for examples. I think he's got a solution, so I'll
    wait for him to follow-up before spending any more time on this.

    Bob
    --
    Microsoft MVP -- ASP/ASP.NET
    Please reply to the newsgroup. The email account listed in my From
    header is my spam trap, so I don't check it very often. You will get a
    quicker response by posting to the newsgroup.
     
    Bob Barrows [MVP], Dec 17, 2004
    #6
  7. Ray Costanzo [MVP] wrote:
    > "Mike D" <> wrote in message
    > news:...
    >
    >> Example
    >> 0.099 is 2 sig figs
    >> 0.000009 is 1

    >
    > I don't remember leading zeros to the right of the decimal not
    > counting as significant. If that's that's one of the rules of
    > significant digits, that doesn't make any sense to me. Why are those
    > zeros any less significant than other numbers when in that position?
    > No wonder I failed chemistry. ;]
    >
    >> .997 is 3

    >
    > That makes sense. But, .007 is just as precise a .997. Maybe I'll
    > see if I can find a Physics textbook or something and read it.
    >

    ..007 = 0.7E-2 so it has one sig fig

    Bob

    --
    Microsoft MVP -- ASP/ASP.NET
    Please reply to the newsgroup. The email account listed in my From
    header is my spam trap, so I don't check it very often. You will get a
    quicker response by posting to the newsgroup.
     
    Bob Barrows [MVP], Dec 17, 2004
    #7
  8. Ray Costanzo [MVP] wrote:
    >> .997 is 3

    >
    > That makes sense. But, .007 is just as precise a .997.


    In addition, yes. In multiplication, no.



    --
    Dave Anderson

    Unsolicited commercial email will be read at a cost of $500 per message. Use
    of this email address implies consent to these terms. Please do not contact
    me directly or ask me to contact you directly for assistance. If your
    question is worth asking, it's worth posting.
     
    Dave Anderson, Dec 17, 2004
    #8
  9. Mike D

    Mike D Guest

    Here is a site that shows some examples

    http://science.widener.edu/svb/tutorial/sigfigures.html

    Yes, I have a solution but I am now fighting my test server it is giving a
    "HTTP 405 - Resource not allowed" error when doing a simple post.

    Mike




    "Ray Costanzo [MVP]" wrote:

    >
    >
    >
    > "Mike D" <> wrote in message
    > news:...
    >
    > > Example
    > > 0.099 is 2 sig figs
    > > 0.000009 is 1

    >
    > I don't remember leading zeros to the right of the decimal not counting as
    > significant. If that's that's one of the rules of significant digits, that
    > doesn't make any sense to me. Why are those zeros any less significant than
    > other numbers when in that position? No wonder I failed chemistry. ;]
    >
    > > .997 is 3

    >
    > That makes sense. But, .007 is just as precise a .997. Maybe I'll see if I
    > can find a Physics textbook or something and read it.
    >
    >
    > Ray at work
    >
    >
    >
     
    Mike D, Dec 20, 2004
    #9
  10. Try specifying the page name to wich you're submitting the form. Even if
    it's default.asp, which I imagine it is, specify that in the form action.

    <form method="post" action="default.asp" ...>

    You cannot do something like:

    <form method="post"> (If the page is loaded as the default document and
    you're at a URL with no document specified)

    or

    <form method="post" action="/directoryName/">

    Ray at work


    "Mike D" <> wrote in message
    news:...
    > Here is a site that shows some examples
    >
    > http://science.widener.edu/svb/tutorial/sigfigures.html
    >
    > Yes, I have a solution but I am now fighting my test server it is giving a
    > "HTTP 405 - Resource not allowed" error when doing a simple post.
    >
    > Mike
    >
    >
     
    Ray Costanzo [MVP], Dec 20, 2004
    #10
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Xiangliang Meng
    Replies:
    1
    Views:
    1,609
    Victor Bazarov
    Jun 21, 2004
  2. Mark Carter
    Replies:
    1
    Views:
    486
    Koczian
    Jul 11, 2003
  3. Ron Stephens
    Replies:
    23
    Views:
    2,857
    Ron Stephens
    Apr 12, 2004
  4. DaveInSidney
    Replies:
    0
    Views:
    423
    DaveInSidney
    May 9, 2005
  5. matchstick86

    sig : process vs. process(sig)

    matchstick86, Oct 12, 2009, in forum: VHDL
    Replies:
    1
    Views:
    565
    power_hf2005
    Oct 13, 2009
Loading...

Share This Page