开发者

C# Comparing float to int

开发者 https://www.devze.com 2023-01-18 13:00 出处:网络
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):

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 f开发者_如何学Cloat)?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消