我想纠正Round函数 [英] I want to correct Round function

查看:95
本文介绍了我想纠正Round函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



System.Math.Round函数让我很困惑。

例如我想用小数符号来回合3.245 in

结果应该是= 3.25


当我在vb中尝试这个时:

A = 3.245

X = Round(A, 2)

然后x = 3.24,结果是假的


但是当我尝试A = 3.235

X = Round (A,2)

然后x = 3.24,结果是真的


所以我怎么能相信这个功能。

或有没有真正的圆函数你知道吗?

不是:通常,我想用小数点后两位(> = 5是向上舍入,< 5

圆了下来)

解决方案

Nomenklatura,


我认为你可以相信这一轮总是根据

文件行事的方法:


"如果价值在两个数字之间,其中一个是偶数,另一个是

奇数,然后返回偶数。


"此方法的行为遵循IEEE标准754第4节。此类

的舍入有时称为四舍五入到最近,或者是银行家的四舍五入。


Kerry Moorman


" nomenklatura"写道:


System.Math.Round函数让我困惑。
例如我想用小数符号来回转3.245 in
结果应该是= 3.25

当我在vb中尝试这个时:
A = 3.245
X = Round(A,2)
然后x = 3.24,结果是是假的

但当我尝试A = 3.235
X = Round(A,2)
然后x = 3.24,结果是真的

那么我怎么能相信这个功能。
或者你知道有没有真正的圆函数吗?
不是:通常,我想用小数点后两位(> = 5是向上舍入,< 5
是圆的)



Kerry,

如果值是两个数字之间的中间值,其中一个是偶数,而其他数字是奇数,则返回偶数。

这种方法遵循IEEE标准754第4节。这种类型的舍入有时是cal导致四舍五入到最近,或者是银行家的四舍五入。



我很好奇这个用在银行业旁边。


这个标准是在你所在的国家使用的,当是的时候,你来自哪个国家?


Cor


"特权阶层" < IL ****** @ operamail.com>在消息中写道

news:eV ************** @ TK2MSFTNGP10.phx.gbl ...

System.Math.Round函数让我很困惑。
例如我想用小数符号来回转3.245结果
结果应该是= 3.25

当我在vb中尝试这个时:A = 3.245
X =圆形(A,2)
然后x = 3.24,结果是假的

但是当我尝试A = 3.235 < br => X =圆形(A,2)
然后x = 3.24,结果是真的

那么我怎么能相信这个功能呢。
还是有真正的圆函数你知道吗?
不是:通常情况下,我想用小数点后两位(> = 5向上舍入,
< 5向下舍入)




在这个例子中,添加0.005并截断。我建议你写一个自己的

圆函数来处理各种小数位(例如,MyRound,或

无论如何)。


Hi,
System.Math.Round function is confused me.
for example i want to round 3.245 in with decimal symbol
Result should be = 3.25

When i try to this in vb:
A = 3.245
X = Round(A, 2)
then x=3.24 , result is is false

But when i try to A = 3.235
X = Round(A, 2)
then x=3.24 , result is true

So how can i trust this function.
Or are there any true round function which you know?
Not: Normally , I want to round with two decimal place (>=5 is round up, <5
is round down)

解决方案

Nomenklatura,

I think you can trust the Round method to always act according to the
documentation:

"If value is halfway between two numbers, one of which is even and the other
odd, then the even number is returned."

"The behavior of this method follows IEEE Standard 754, section 4. This kind
of rounding is sometimes called rounding to nearest, or banker''s rounding."

Kerry Moorman

"nomenklatura" wrote:

Hi,
System.Math.Round function is confused me.
for example i want to round 3.245 in with decimal symbol
Result should be = 3.25

When i try to this in vb:
A = 3.245
X = Round(A, 2)
then x=3.24 , result is is false

But when i try to A = 3.235
X = Round(A, 2)
then x=3.24 , result is true

So how can i trust this function.
Or are there any true round function which you know?
Not: Normally , I want to round with two decimal place (>=5 is round up, <5
is round down)



Kerry,

"If value is halfway between two numbers, one of which is even and the
other
odd, then the even number is returned."

"The behavior of this method follows IEEE Standard 754, section 4. This
kind
of rounding is sometimes called rounding to nearest, or banker''s
rounding."


I am curious where this is used beside banking.

Is this standard used in your country and when yes, from what country are
you?

Cor


"nomenklatura" <il******@operamail.com> wrote in message
news:eV**************@TK2MSFTNGP10.phx.gbl...

Hi,
System.Math.Round function is confused me.
for example i want to round 3.245 in with decimal symbol
Result should be = 3.25

When i try to this in vb:
A = 3.245
X = Round(A, 2)
then x=3.24 , result is is false

But when i try to A = 3.235
X = Round(A, 2)
then x=3.24 , result is true

So how can i trust this function.
Or are there any true round function which you know?
Not: Normally , I want to round with two decimal place (>=5 is round up, <5 is round down)



In this instance, add 0.005 and truncate. I would suggest writing your own
round function to handle various decimal places (e.g., MyRound, or
whatever).


这篇关于我想纠正Round函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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