473,791 Members | 3,216 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1738
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 "significan t 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(aNumbers Used, dblResult)
Function SigFig(ArrayOfN umbers, Result)
Dim i, s
Dim iSigCount
Dim iMinSigs
Dim sResult, aResult, iInteger, iDecimal

iMinSigs = 99
For i = 0 To UBound(ArrayOfN umbers, 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***@discussi ons.microsoft.c om> wrote in message
news:83******** *************** ***********@mic rosoft.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 "significan t 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***@discussi ons.microsoft.c om> wrote in message
news:B7******** *************** ***********@mic rosoft.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***@discussi ons.microsoft.c om> wrote in message
news:B7******** *************** ***********@mic rosoft.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***@discussi ons.microsoft.c om> wrote in message
news:B7******** *************** ***********@mic rosoft.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***@discussi ons.microsoft.c om> wrote in message
news:B7******** *************** ***********@mic rosoft.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***@discussi ons.microsoft.c om> wrote in message
news:E4******** *************** ***********@mic rosoft.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
1260
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 products for the selected supplier.
0
1020
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 products for the selected supplier.
14
2841
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 number) linking (and sometimes compiling) becomes immensely slow, and task manager shows that link.exe (or cl.exe) is barely using any processor time, but an awful lot of RAM (around 150-200MB). I'm going to keep an eye on page faults since I can't...
32
1715
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 displayed. I see: -- the code is creating DIV's and -- overrides are hidden
11
2822
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 have come up with this API so far and will welcome any feedback on it. In particular, I will need help with implementing the linked lists used for record keeping as to which blocks were free or not (and for "defragging" the pool when "holes"...
0
9669
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
10156
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9030
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7537
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6776
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5435
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5559
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4110
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3718
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.