关于sig fig功能的脚本重新发布 [英] repost from scripting about sig fig functions

查看:125
本文介绍了关于sig fig功能的脚本重新发布的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一个可以使用适当数量的sig格式化数字的函数

figs。 Ideallty一个函数,它接受两个值转换的值

和我希望它格式化的sig figs的数量。有没有人这样做过?

如何获得任何线索?我一直在网上找不到

任何东西。

谢谢

迈克

解决方案

Mike D写道:

我需要一个能够用适当的sig figs格式化数字的函数。 Ideallty一个函数,它将两个值转换为要转换的值和我希望它格式化的sig figs的数量。有没有人这样做过?任何线索如何?我一直在网上搜索,但还没有找到任何东西。



sig figs?你的意思是有效数字吗?在真正的科学意义上

这个词?也许你应该发布一些例子,所以我们都在相同的

页面。显示一些数字然后显示你想要的输出

不同的sig fig价值。


Bob Barrows

-

Microsoft MVP - ASP / ASP.NET

请回复新闻组。我的From

标题中列出的电子邮件帐户是我的垃圾邮件陷阱,因此我不经常检查它。通过发布到新闻组,您将获得更快的回复。


自从我听到任何人以来已经过了大约13年提到sig figs,

假设你的行话是我认为的那样。 (

科学数学中的重要数字?)


喜欢,你的意思是这个吗?


3.45 * 1.2 = 4.1

而不是

3.45 * 1.2 = 4.14


如果是这样,你打算如何将参数传递给功能?算术运算中使用的一组

数字和结果?比如,你会这样做:


Dim aNumbersUsed(1)

Dim dblResult

aNumbersUsed(0)=" 3.45" ; '''''作为字符串传递,而不是数字符号

aNumbersUsed(1)=" 1.2"

dblResult = 4.14''''或算术运算在这里

Response.Write SigFig(aNumbersUsed,dblResult)

函数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)

如果Int(s)= CDbl(s)那么''''没有小数

''''cdbl阻止前导零计数,

''''虽然我不明白为什么他们会在那里。 :]

iSigCount = Len(CStr(CDbl(s)))

Else''''十进制数

''''得到十进制前后的长度

iSigCount = Len(CStr(Int(s)))+ Len(CStr(Split(s,。)(1)))

结束如果


''''如果sigcount低于它的最后一次循环,则需要花费b / b''''那就是

''''当前返回的有效位数

如果iSigCount< iMinSigs然后iMinSigs = iSigCount

下一页


''''现在我们可能有正确的有效位数,所以

''''我们可以取结果并表示它

''''我不记得所有具体规则

''''有效数字。 />
''''我想第二步将涉及分割由...传递的结果。
''''角色

''''并用零或四舍五入测试LEN和填充


''''现在,我只返回数字有效数字

如果iMinSigs = 99那么

''''找不到有效数字

SigFig ="你没有意义传递给这个

函数。

退出函数

Else

SigFig = iMinSigs

结束如果

结束功能

雷在工作


" Mike D" <弥*** @ discussions.microsoft.com>在消息中写道

news:83 ********************************** @ microsof t.com ...

我需要一个能够使用适当数量的
sig figs格式化数字的函数。 Ideallty一个函数,它接受要转换的值的两个值
和我想要格式化的sig figs的数量。有没有人这样做过?
任何线索如何?我一直在网上搜索,还没找到
任何东西。

谢谢
Mike



< blockquote>" Bob Barrows [MVP]"写道:

" sig figs"?你的意思是有效数字吗?在真正的科学意义上这个词?




是的,我们讨厌科学的所有事情。


例子

0.099是2 sig figs

0.000009是1

..997是3


我需要拿一个像0.0000099734的数字并转换成各种各样的

sig figs。意思是一些变量需要2个,一些3个等等。所以我不能只用一个级别来写

。我已经找到了
http:// www.vbforums.com/showthread.p...hreadid=269312


我正在测试它。


谢谢你回复



也许您应该发布一些示例,以便我们都在同一页面上。显示一些数字然后显示你想要的输出
不同的sig fig值得。

Bob Barrows
-
Microsoft MVP - ASP / ASP.NET
请回复新闻组。我的From
标题中列出的电子邮件帐户是我的垃圾邮件陷阱,因此我不经常检查它。通过发布到新闻组,您将得到更快的回复。



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


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



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



这篇关于关于sig fig功能的脚本重新发布的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆