如何判断小数或双精度值是否为整数?
例如:
decimal d = 5.0; // Would be true
decimal f = 5.5; // Would be false
Run Code Online (Sandbox Code Playgroud)
要么
double d = 5.0; // Would be true
double f = 5.5; // Would be false
Run Code Online (Sandbox Code Playgroud)
我想知道这个的原因是我可以通过编程方式确定是否要使用.ToString("N0")或输出值.ToString("N2").如果没有小数点值,那么我不想显示.
是否有可能做到这一点?
double variable;
variable = 5;
/* the below should return true, since 5 is an int.
if variable were to equal 5.7, then it would return false. */
if(variable == int) {
//do stuff
}
Run Code Online (Sandbox Code Playgroud)
我知道代码可能不会去这样的事情,但怎么也去了?