感谢您的帮助。Hi all,I Have run this test:Private Sub test()Dim d As DoubleDim f As SingleDim output As Stringd = 8888888888888.8887f = 9999999988888.8887output = "Original double is: " & d.ToString() & " FormatedDouble is: " & FormatNumber(d, 2, TriState.True) & vbCrLf _& "Original single is: " & f.ToString() & "Formated Single is: "& FormatNumber(f, 2, TriState.True)MsgBox(output)End SubThe result is this:Original Double is: 8888888888888.8887 Formated Double is:8.888.888.888.888,89Original Single is: 1E+13 Formated Single is 10.000.000.000.000,00Now 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 maybemore pages than the Phone book of by instance New York.Cor<al**********@gmail.comschreef in berichtnews: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() & " FormatedDouble is: " & FormatNumber(d, 2, TriState.True) & vbCrLf _ & "Original single is: " & f.ToString() & "Formated Single is: "& FormatNumber(f, 2, TriState.True) MsgBox(output) End SubThe result is this:Original Double is: 8888888888888.8887 Formated Double is:8.888.888.888.888,89Original Single is: 1E+13 Formated Single is 10.000.000.000.000,00Now 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, alsmeirellesI don''t think this has anything to do with "rounding" per se. It isnormal behaviour for floating point numbers.Suggested reading: http://docs.sun.com/source/806-3568/ncg_goldberg.htmlCheers,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() & " FormatedDouble is: " & FormatNumber(d, 2, TriState.True) & vbCrLf _ & "Original single is: " & f.ToString() & "Formated Single is: "& FormatNumber(f, 2, TriState.True) MsgBox(output) End SubThe result is this:Original Double is: 8888888888888.8887 Formated Double is:8.888.888.888.888,89Original Single is: 1E+13 Formated Single is 10.000.000.000.000,00Now 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 withthe double variable is perfect.My question is about the behavior of the single. See, the originalnumber 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 ofrepresentability they have in binary bases. For example,there''s no way to express exactly 0.1 in binary. Although I haven''tread the suggested article yet (but I willl), I think that its mainsubject is about this lack of representability and what happens tothe numbers when they are in the edge of an overflow (which is not thecase here). So, I consider that my question is a little more trickythan "it''s the bankers rounding that does this".Of course, I know very little of the .Net framework, and I may be anignorant concerning floating-points, so, any help is welcome.Regards,AlsmOn Feb 15, 10:13 pm, "R. MacDonald" <[email protected]: 你好,alsmeirelles 我不喜欢认为这与四舍五入有关本身。这是浮点数的正常行为。 建议读数: http://docs.sun.com/source/806-3568/ncg_goldberg.html 干杯, 兰迪 alsmeirel ... @ gmail.com写道:Hello, alsmeirellesI don''t think this has anything to do with "rounding" per se. It isnormal behaviour for floating point numbers.Suggested reading:http://docs.sun.com/source/806-3568/ncg_goldberg.htmlCheers,[email protected] 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. 这篇关于真的很奇怪的四舍五入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
09-02 08:51