真的很奇怪的四舍五入 [英] Really weird rounding

查看:64
本文介绍了真的很奇怪的四舍五入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


我参加过这个测试:


私人子测试()

昏暗d As Double

Dim f As Single

Dim output As String


d = 8888888888888.8887

f = 9999999988888.8887

output ="原来的双倍是: &安培; d.ToString()& " Formated

Double是: &安培; FormatNumber(d,2,TriState.True)& vbCrLf _

& 原始单身是: &安培; f.ToString()& Formated Single is:

& FormatNumber(f,2,TriState.True)


MsgBox(输出)

结束子

结果如下:


原装双人间:8888888888888.8887 Formated Double是:

8.888.888.888.888,89

原单是:1E + 13 Formated Single是10.000.000.000.000,00


现在出现了一个大问题:

为什么将9999999988888.8887四舍五入为10.000.000.000.000,00

(或1E + 13科学记数法)?


此测试在VB.Net 2003,1.1 Framework中运行。

感谢您的帮助。

Hi all,

I Have run this test:

Private Sub test()
Dim d As Double
Dim f As Single
Dim output As String

d = 8888888888888.8887
f = 9999999988888.8887

output = "Original double is: " & d.ToString() & " Formated
Double is: " & FormatNumber(d, 2, TriState.True) & vbCrLf _
& "Original single is: " & f.ToString() & "Formated Single is: "
& FormatNumber(f, 2, TriState.True)

MsgBox(output)
End Sub
The result is this:

Original Double is: 8888888888888.8887 Formated Double is:
8.888.888.888.888,89
Original Single is: 1E+13 Formated Single is 10.000.000.000.000,00

Now cames the big question:
How come that 9999999988888.8887 was rounded to 10.000.000.000.000,00
(or 1E+13 in scientific notation)?

This test was run in VB.Net 2003, 1.1 Framework.

Thanks for any help.

推荐答案

Alsmeirelles,


Not在dotNet新闻组写的很奇怪和成千上万的时间。


在dotNet中使用的是ISO银行家四舍五入。不像人类那样做。


如果你在谷歌和C#新闻组中搜索这个,你可能会比电话簿更多页面b
例如纽约。


Cor

< al ********** @ gmail.comschreef in bericht

news:11 ********************** @ j27g2000cwj.googlegr oups.com ...
Alsmeirelles,

Not weird and thousands of time written in the dotNet newsgroup.

In dotNet is ISO bankers rounding used. Not the way as humans do it.

If you search for this in this and the C# newsgroup on Google you get maybe
more pages than the Phone book of by instance New York.

Cor
<al**********@gmail.comschreef in bericht
news:11**********************@j27g2000cwj.googlegr oups.com...

大家好,


我参加过这个测试:


私人子测试()

Dim d As Double

Dim f As Single

Dim output As String


d = 8888888888888.8887

f = 9999999988888.8887

output ="原来的双倍是:" &安培; d.ToString()& " Formated

Double是: &安培; FormatNumber(d,2,TriState.True)& vbCrLf _

& 原始单身是: &安培; f.ToString()& Formated Single is:

& FormatNumber(f,2,TriState.True)


MsgBox(输出)

End Sub


结果是这样:


原装双人间:8888888888888.8887 Formated Double是:

8.888.888.888.888,89

Original Single is :1E + 13 Formated Single是10.000.000.000.000,00


现在出现了一个大问题:

为什么9999999988888.8887被舍入到10.000.000.000 .000,00

(或1E + 13科学计数法)?


此测试在VB.Net 2003,1.1 Framework中运行。


感谢您的帮助。
Hi all,

I Have run this test:

Private Sub test()
Dim d As Double
Dim f As Single
Dim output As String

d = 8888888888888.8887
f = 9999999988888.8887

output = "Original double is: " & d.ToString() & " Formated
Double is: " & FormatNumber(d, 2, TriState.True) & vbCrLf _
& "Original single is: " & f.ToString() & "Formated Single is: "
& FormatNumber(f, 2, TriState.True)

MsgBox(output)
End Sub
The result is this:

Original Double is: 8888888888888.8887 Formated Double is:
8.888.888.888.888,89
Original Single is: 1E+13 Formated Single is 10.000.000.000.000,00

Now cames the big question:
How come that 9999999988888.8887 was rounded to 10.000.000.000.000,00
(or 1E+13 in scientific notation)?

This test was run in VB.Net 2003, 1.1 Framework.

Thanks for any help.



您好,alsmeirelles


我不认为这与四舍五入有关本身。这是浮点数的正常行为。


建议读数: http://docs.sun.com/source/806-3568/ncg_goldberg.html


干杯,

兰迪
al ******* ***@gmail.com 写道:
Hello, alsmeirelles

I don''t think this has anything to do with "rounding" per se. It is
normal behaviour for floating point numbers.

Suggested reading: http://docs.sun.com/source/806-3568/ncg_goldberg.html

Cheers,
Randy
al**********@gmail.com wrote:

大家好,


我已经运行了这个测试:


私人子测试()

Dim d As Double

Dim f As Single

Dim输出为字符串


d = 8888888888888.8887

f = 9999999988888.8887

output ="原来的双倍是:" &安培; d.ToString()& " Formated

Double是: &安培; FormatNumber(d,2,TriState.True)& vbCrLf _

& 原始单身是: &安培; f.ToString()& Formated Single is:

& FormatNumber(f,2,TriState.True)


MsgBox(输出)

End Sub


结果是这样:


原装双人间:8888888888888.8887 Formated Double是:

8.888.888.888.888,89

Original Single is :1E + 13 Formated Single是10.000.000.000.000,00


现在出现了一个大问题:

为什么9999999988888.8887被舍入到10.000.000.000 .000,00

(或1E + 13科学计数法)?


此测试在VB.Net 2003,1.1 Framework中运行。


感谢您的帮助。
Hi all,

I Have run this test:

Private Sub test()
Dim d As Double
Dim f As Single
Dim output As String

d = 8888888888888.8887
f = 9999999988888.8887

output = "Original double is: " & d.ToString() & " Formated
Double is: " & FormatNumber(d, 2, TriState.True) & vbCrLf _
& "Original single is: " & f.ToString() & "Formated Single is: "
& FormatNumber(f, 2, TriState.True)

MsgBox(output)
End Sub
The result is this:

Original Double is: 8888888888888.8887 Formated Double is:
8.888.888.888.888,89
Original Single is: 1E+13 Formated Single is 10.000.000.000.000,00

Now cames the big question:
How come that 9999999988888.8887 was rounded to 10.000.000.000.000,00
(or 1E+13 in scientific notation)?

This test was run in VB.Net 2003, 1.1 Framework.

Thanks for any help.





我不认识VB。 Net使用银行家四舍五入,完成了什么。

双变量是完美的。

我的问题是关于单身的行为。看,原来

的数字是9999999988888.8887。


绝不可能转换为10.000.000.000.000,00。


而且,正如R.MacDonald所说,它是真正的浮点数,而且是b $ b奇怪的行为有时候,主要是因为他们在二元基础上缺乏表示能力。例如,

没有办法用二进制表示正好0.1。虽然我还没有阅读建议的文章(但我会),我认为其主要的b $ b $主题是关于这种缺乏可表示性以及

当它们处于溢出边缘时的数字(这不是

的情况)。因此,我认为我的问题有点棘手

而不是这是银行家四舍五入这样做。


当然,我对.Net框架知之甚少,而且我可能对浮点数一无所知,所以,欢迎任何帮助。


问候,

Alsm


2月15日晚上10点13分,R。麦克唐纳" < sci ... @ NO-SP-AMcips.cawrote:


I undestand that VB.Net uses the bankers rounding, what was done with
the double variable is perfect.
My question is about the behavior of the single. See, the original
number was 9999999988888.8887 .

In no way it could have been converted to 10.000.000.000.000,00.

And, as R.MacDonald said, it''s true floating-point numbers have
"strange" behaviors sometimes, basically due to the lack of
representability they have in binary bases. For example,
there''s no way to express exactly 0.1 in binary. Although I haven''t
read the suggested article yet (but I willl), I think that its main
subject is about this lack of representability and what happens to
the numbers when they are in the edge of an overflow (which is not the
case here). So, I consider that my question is a little more tricky
than "it''s the bankers rounding that does this".

Of course, I know very little of the .Net framework, and I may be an
ignorant concerning floating-points, so, any help is welcome.

Regards,
Alsm

On Feb 15, 10:13 pm, "R. MacDonald" <sci...@NO-SP-AMcips.cawrote:

你好,alsmeirelles


我不喜欢认为这与四舍五入有关本身。这是浮点数的正常行为。


建议读数: http://docs.sun.com/source/806-3568/ncg_goldberg.html


干杯,

兰迪


alsmeirel ... @ gmail.com写道:
Hello, alsmeirelles

I don''t think this has anything to do with "rounding" per se. It is
normal behaviour for floating point numbers.

Suggested reading:http://docs.sun.com/source/806-3568/ncg_goldberg.html

Cheers,
Randy

alsmeirel...@gmail.com wrote:

大家好,
Hi all,


我已经运行了这个测试:
I Have run this test:


私人子测试()

Dim d As Double

Dim f As Single

Dim output As String
Private Sub test()
Dim d As Double
Dim f As Single
Dim output As String


d = 8888888888888.8887

f = 9999999988888.8887
d = 8888888888888.8887
f = 9999999988888.8887


output =" Original double是: &安培; d.ToString()& " Formated

Double是: &安培; FormatNumber(d,2,TriState.True)& vbCrLf _

& 原始单身是: &安培; f.ToString()& Formated Single is:

& FormatNumber(f,2,TriState.True)
output = "Original double is: " & d.ToString() & " Formated
Double is: " & FormatNumber(d, 2, TriState.True) & vbCrLf _
& "Original single is: " & f.ToString() & "Formated Single is: "
& FormatNumber(f, 2, TriState.True)


MsgBox(输出)

End Sub
MsgBox(output)
End Sub


结果如下:
The result is this:


原始双人间是:8888888888888.8887 Formated Double是:

8.888.888.888.888,89

原单是:1E + 13 Formated Single是10.000.000.000.000,00
Original Double is: 8888888888888.8887 Formated Double is:
8.888.888.888.888,89
Original Single is: 1E+13 Formated Single is 10.000.000.000.000,00


现在出现了一个大问题:

为什么将9999999988888.8887舍入到10.000.000.000.000,00

(或1E + 13 in科学计数法)?
Now cames the big question:
How come that 9999999988888.8887 was rounded to 10.000.000.000.000,00
(or 1E+13 in scientific notation)?


此测试在VB.Net 2003,1.1 Framework中运行。
This test was run in VB.Net 2003, 1.1 Framework.


感谢您的帮助。
Thanks for any help.



这篇关于真的很奇怪的四舍五入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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