IIS ASP - repost from scripting about sig fig functions

This is Interesting: Free IT Magazines  
Home > Archive > IIS ASP > December 2004 > repost from scripting about sig fig functions





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author repost from scripting about sig fig functions
Mike D

2004-12-17, 5:52 pm

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

Bob Barrows [MVP]

2004-12-17, 5:52 pm

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.


Ray Costanzo [MVP]

2004-12-17, 5:52 pm

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" <MikeD@discussions.microsoft.com> wrote in message
news:83D7E949-FB41-4B64-90CD-B31AE89A9CB0@microsoft.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
>



Mike D

2004-12-17, 5:52 pm

"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....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.
>
>
>

Ray Costanzo [MVP]

2004-12-17, 5:52 pm




"Mike D" <MikeD@discussions.microsoft.com> wrote in message
news:B7A836E7-C3F7-44F5-9A27-FA4DD4FE85A8@microsoft.com...

> 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


Bob Barrows [MVP]

2004-12-17, 5:52 pm

Ray Costanzo [MVP] wrote:
> "Mike D" <MikeD@discussions.microsoft.com> wrote in message
> news:B7A836E7-C3F7-44F5-9A27-FA4DD4FE85A8@microsoft.com...
>
>
> 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]

2004-12-17, 5:52 pm

Ray Costanzo [MVP] wrote:
> "Mike D" <MikeD@discussions.microsoft.com> wrote in message
> news:B7A836E7-C3F7-44F5-9A27-FA4DD4FE85A8@microsoft.com...
>
>
> 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. ;]
>
>
> 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.


Dave Anderson

2004-12-17, 5:52 pm

Ray Costanzo [MVP] wrote:
>
> 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.


Mike D

2004-12-20, 5:50 pm

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" <MikeD@discussions.microsoft.com> wrote in message
> news:B7A836E7-C3F7-44F5-9A27-FA4DD4FE85A8@microsoft.com...
>
>
> 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. ;]
>
>
> 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]

2004-12-20, 5:50 pm

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" <MikeD@discussions.microsoft.com> wrote in message
news:E478740B-5BFE-44B2-BEC9-D3AF334A836E@microsoft.com...
> 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
>
>



Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com