473,320 Members | 1,862 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

repost from scripting about sig fig functions

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

Jul 22 '05 #1
9 1723
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.
Jul 22 '05 #2
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" <Mi***@discussions.microsoft.com> wrote in message
news:83**********************************@microsof t.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

Jul 22 '05 #3
"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.p...hreadid=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.

Jul 22 '05 #4

"Mike D" <Mi***@discussions.microsoft.com> wrote in message
news:B7**********************************@microsof t.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
Jul 22 '05 #5
Ray Costanzo [MVP] wrote:
"Mike D" <Mi***@discussions.microsoft.com> wrote in message
news:B7**********************************@microsof t.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.


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.
Jul 22 '05 #6
Ray Costanzo [MVP] wrote:
"Mike D" <Mi***@discussions.microsoft.com> wrote in message
news:B7**********************************@microsof t.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.

..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.
Jul 22 '05 #7
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.
Jul 22 '05 #8
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" <Mi***@discussions.microsoft.com> wrote in message
news:B7**********************************@microsof t.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

Jul 22 '05 #9
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" <Mi***@discussions.microsoft.com> wrote in message
news:E4**********************************@microsof t.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

Jul 22 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Fresh Air Rider | last post by:
Hi Everyone Scenario A Webage has two dropdown lists, one for Suppliers and one for Products. When a user selects a supplier, it then populates the Products dropdown list with the relevant...
0
by: Fresh Air Rider | last post by:
Hi Everyone Scenario A Webage has two dropdown lists, one for Suppliers and one for Products. When a user selects a supplier, it then populates the Products dropdown list with the relevant...
14
by: Steve McLellan | last post by:
Hi, Sorry to repost, but this is becoming aggravating, and causing me a lot of wasted time. I've got a reasonably large mixed C++ project, and after a number of builds (but not a constant...
32
by: Jon Paal | last post by:
trying to use this script for scrolling tables found at this link: http://www.litotes.demon.co.uk/example_scripts/tableScroll.html The top left corner in the table grid is hidden from being...
11
by: Grey Alien | last post by:
I am looking to write a very simple memory pool library to store only one data type at a time - i.e. to provide a contiguous block of memory to be alloc'd free'd by the calling program. I am I...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.