检查值是否为整数(Objective-C)

时间:2022-08-08 22:52:34

How do I check if my value is a integer or not?
I want something like this:

如何检查值是否为整数?我想要这样的东西:


if ( i/split != int )  {...}

Thanks,

谢谢,

2 个解决方案

#1


8  

I'm not sure but I think you're trying to find out if the result of the divide is a whole number. You can use modulus operator % to get the remainder from the divide operation.

我不确定,但我想你们是想知道除以的结果是不是一个整数。您可以使用模数运算符%从除运算中获得余数。

Assuming i and split are integer types (int, long, short, etc), then modulus returns 0 when i or split is an integer value, ie:

假设i和split是整数类型(int, long, short等),那么当i或split为整数时,模数返回0,即:

if ( i % split == 0 ) {...}

#2


1  

Just use the objCType method? Docs

使用objCType方法?文档

#1


8  

I'm not sure but I think you're trying to find out if the result of the divide is a whole number. You can use modulus operator % to get the remainder from the divide operation.

我不确定,但我想你们是想知道除以的结果是不是一个整数。您可以使用模数运算符%从除运算中获得余数。

Assuming i and split are integer types (int, long, short, etc), then modulus returns 0 when i or split is an integer value, ie:

假设i和split是整数类型(int, long, short等),那么当i或split为整数时,模数返回0,即:

if ( i % split == 0 ) {...}

#2


1  

Just use the objCType method? Docs

使用objCType方法?文档