C# 比较 float 和 int

发布于 2024-09-25 19:25:24 字数 260 浏览 0 评论 0原文

我看到这段代码漂浮在管间上,用于确定 Windows Mobile 设备是否具有 VGA 屏幕(代码位于 Form 类的方法内):

SizeF currentScreen = this.CurrentAutoScaleDimensions;
bool isVGA = currentScreen.Height == 192;

即使屏幕是 VGA,是否可能将 isVGA 设置为 false,因为浮点数不精确(Height 属性是浮点数)?

I have seen this code floating around on the intertubes for determining if a Windows Mobile device has a VGA screen (code is inside a method of a Form class):

SizeF currentScreen = this.CurrentAutoScaleDimensions;
bool isVGA = currentScreen.Height == 192;

Is it possible that isVGA could be set to false even if the screen is VGA because of float imprecision (the Height property is a float)?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

枕梦 2024-10-02 19:25:24

不在您提供的示例中,因为(符合 IEEE 754 标准,32 位)浮点数 能够准确表示绝对值小于等于2^24的所有整数(整数)

Not in the example you present, because (IEEE 754-compliant, 32-bit) floating-point numbers can accurately represent all integers (whole numbers) whose absolute value is less than or equal to 2^24.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文