我想检查一个浮点变量的数字长度,但我不知道要使用的正确语法。我看了这个,我找不到答案。检查一个浮点数的长度
我的代码是一个简单的if语句:从长度
NSString *stringNumber = [NSString stringWithFormat:@"%g", currentValue];
int length = stringNumber.length
你或许可以减去1:
if (currentNumber.digits < 3) { //If the number has less that three digits, I don't know what to put here to get it working
//code
}
你说的长度是什么意思?你的意思是小数点前的数字吗?只是之后的?或者全部都是? – Jodaka 2012-07-06 17:04:13
对不起,只是小数点前的那个。 – Fernald 2012-07-06 17:04:52
您可以四舍五入(小数)十进制日志来获取您的位数。 – 2012-07-06 17:06:20