C# 比较 float 和 int

sti*_*g_1 5 c# floating-point compact-framework windows-mobile

我已经看到这段代码在 intertubes 上浮动,用于确定 Windows Mobile 设备是否具有 VGA 屏幕(代码位于 Form 类的方法中):

SizeF currentScreen = this.CurrentAutoScaleDimensions;
bool isVGA = currentScreen.Height == 192;
Run Code Online (Sandbox Code Playgroud)

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

Mic*_*tta 4

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