如何使双打正常工作? C#

编程入门 行业动态 更新时间:2024-10-24 13:20:16
本文介绍了如何使双打正常工作? C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

这是代码:

static void Main(string[] args) { int xd2 = 5; for (double xd = (double)xd2; xd <= 6; xd += 0.01) { Console.WriteLine(xd); } }

这是输出:

and here's the output:

我想继续添加0.01(如您在屏幕上看到的那样,有时恰好添加0.99999)谢谢

I want to keep on adding 0.01 (as You can see on the screen, sometimes it happens to add 0.99999) Thanks

推荐答案

如果需要,使用 十进制 为了保持这种准确性。

Use decimal if you want to keep this kind of accuracy.

浮点类型不能准确表示某些值。我建议阅读每个计算机科学家应该了解的有关浮点算法的内容,

Floating point types cannot accurately represent certain values. I suggest reading What Every Computer Scientist Should Know About Floating-Point Arithmetic for a comprehensive explanation.

decimal xd2 = 5m; for (decimal xd = xd2; xd <= 6m; xd += 0.01m) { Console.WriteLine(xd); }

更多推荐

如何使双打正常工作? C#

本文发布于:2023-11-17 07:29:56,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1609305.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:双打   工作

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!