舍入程序 [英] Rounding routine
问题描述
任何机会,任何人都有一个四舍五入的例程,围绕VB进行工作
" round" bug?
我仍然觉得像微软那样大的公司会推出一个非常有问题的数学包。
By any chance, anyone got a rounding routine that does a work around the VB
"round" bug?
I still find it amazing that a company as large as Microsoft would put out a
math package that is so problematic.
推荐答案
>任何机会,任何人都有一个四舍五入的例程,可以解决VB
> By any chance, anyone got a rounding routine that does a work around
the VB
" round" bug?
我仍然觉得像微软这么大的公司会把
放在一个有问题的数学软件包中,这真是太神奇了。
"round" bug?
I still find it amazing that a company as large as Microsoft would put out a math package that is so problematic.
It这不是一个错误,只是(在我看来)他们的一个愚蠢的决定。
无论如何,使用格式函数(没有格式说明符),因为它使用
正常四舍五入而不是银行家的舍入(你将其称为错误)。例如,
Debug.Print格式(2.5)
Rick - MVP
It''s not a bug, just (in my opinion) a dumb decision on their part.
Anyway, use the Format function (without a format specifier) as it uses
"normal" rounding rather than the Banker''s Rounding (which you are
referring to as a "bug"). For example,
Debug.Print Format(2.5)
Rick - MVP
2004年6月26日星期六04:15:15 -0400,Rick Rothstein
< ri ************ @ NOSPAMcomcast达网络>写道:
On Sat, 26 Jun 2004 04:15:15 -0400, "Rick Rothstein"
<ri************@NOSPAMcomcast.net> wrote:
无论如何,任何人都有一个舍入程序可以解决
By any chance, anyone got a rounding routine that does a work around
VB
the VB
round bug?
我仍然觉得像微软那样大的公司会把
"round" bug?
I still find it amazing that a company as large as Microsoft would put
排除在
数学包之外,这很有问题。
math package that is so problematic.
这不是一个错误,只是(在我看来)他们的一个愚蠢的决定。
无论如何,使用格式函数(没有格式说明符),因为它使用
"正常"四舍五入而不是银行家的舍入(你将其称为错误)。例如,
It''s not a bug, just (in my opinion) a dumb decision on their part.
Anyway, use the Format function (without a format specifier) as it uses
"normal" rounding rather than the Banker''s Rounding (which you are
referring to as a "bug"). For example,
这很有趣,我为银行做了很多工作
- 并且没有一个使用''银行家舍入''
最重要的是保持''对称四舍五入''
例如:2,000,000.5和-2,000,000.5
无论是什么标志都要转到2,000,001
对于会计师和银行家来说,减号只是意味着''借记''
- 可以借记一个信用账户或信用卡借记账户
所有发生的事情都是+/-标志被颠倒
我遇到的唯一真正特殊的规则是OAT(法国财政部) />
债券)其中将每个债券的利息四舍五入至3 dp之前
乘以债券数量
....和Jap债券
乘以之前,单位利息被截断为7dp。
(与我怀疑的grotty计算器有关)
It is funny, I have done quite a lot of work for banks
- and none of them used ''Bankers Rounding''
The most important thing was to keep ''symetrical rounding''
eg: 2,000,000.5 and -2,000,000.5
both round to 2,000,001 regardless of sign
To accountants and bankers the minus sign just means ''Debit''
- one can Debit a Credit Account or Credit a Debit account
all that happens is that the +/- signs are reversed
The only really peculiar rules I ran into were OATs (French Treasury
Bonds) where one rounded the interest per bond to 3 dp before
multiplying by the number of bonds
.... and Jap bonds where the unit interest is truncated to 7dp before
multiplying.
( something to do with grotty calculators I suspect )
>
" Rick Rothstein" < RI ************ @ NOSPAMcomcast.net>在消息中写道
news:v - ******************** @ comcast.com ...
"Rick Rothstein" <ri************@NOSPAMcomcast.net> wrote in message
news:v-********************@comcast.com...
无论如何,任何人都有一个四舍五入的例程来解决
By any chance, anyone got a rounding routine that does a work around
VB
the VB
" round" bug?
我仍然觉得像微软那样大的公司会把
"round" bug?
I still find it amazing that a company as large as Microsoft would put
排除在
数学包之外,这很有问题。
math package that is so problematic.
这不是一个错误,只是(在我看来)他们的一个愚蠢的决定。
无论如何,使用格式函数(没有格式说明符),因为它使用
正常四舍五入而不是银行家的舍入(你将其称为错误)。例如,
Debug.Print格式(2.5)
Rick - MVP
It''s not a bug, just (in my opinion) a dumb decision on their part.
Anyway, use the Format function (without a format specifier) as it uses
"normal" rounding rather than the Banker''s Rounding (which you are
referring to as a "bug"). For example,
Debug.Print Format(2.5)
Rick - MVP
谢谢Rick ..
不,我不是指银行家的四舍五入,我指的是VB内部
糟糕的浮点错误。
由于
底层代码中存在错误,导致VB的数学函数出现问题。例如,如果你这样做?
?圆形(68.505,2)
你得到68.5,这是不正确的;因为如果你将68.505舍入到两位小数
分,你应该得到68.51。
这是因为计算的基础代码:
? int(68.505 * 100 + .5)/ 100
给出68.5!
这里可以看到一个更严重的错误:
? int(68.505 * 1000 + 5)
68509 !!! (应该是68510)
因此,分数的乘法因子越大,误差越大
(上述误差是一个完整的一个)。
但是没关系,如果没有人准备就绪,我会写一个,我会发布它/
分享它与其他人一起完成。
Thanks Rick..
No I am not referring to banker''s rounding, I am referring to VB internal
lousy floating point errors.
VB''s ailment in its math function is caused because there are errors in the
underlying code. For example, if you do
? round (68.505,2)
you get 68.5, which is incorrect; for if you round 68.505 to two decimal
points you should get 68.51.
This is caused because the underlying code that computes:
? int(68.505 * 100 + .5)/100
gives 68.5!
A more serious error can be seen here:
? int(68.505 * 1000 + 5)
68509 !!! (should have been 68510)
So the bigger the multiplication factor of a fraction, the larger the error
(the above error is a full ONE).
But that''s OK, if no one have one ready, I''ll write one and I''ll post it /
share it with everyone else when done.
这篇关于舍入程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!