我在分隔 9 位数字中的数字时遇到问题。我正在使用以下方法执行此操作:
注意:将 thuis 粘贴到 Xcode 中以更容易地“查看”它可能更容易:
int firstDigit = currentValue *.00000001; // = 3.7 = 3
firstDigitLabel.text = [NSString stringWithFormat:@"%d",firstDigit];
int secondDigit = (currentValue *.0000001) - (firstDigit *10); // = 7.2 = 7
secondDigitLabel.text = [NSString stringWithFormat:@"%d",secondDigit];
int thirdDigit = (currentValue *.000001) - ((firstDigit *100)+(secondDigit*10)); // = 2.8 = 2
thirdDigitLabel.text = [NSString stringWithFormat:@"%d",thirdDigit];
int fourthDigit = (currentValue *.00001) - ((firstDigit *1000)+(secondDigit*100)+(thirdDigit*10)); // = 2.8 = 2
fourthDigitLabel.text = [NSString stringWithFormat:@"%d",fourthDigit];
int fifthDigit = (currentValue *.0001) - ((firstDigit *10000)+(secondDigit*1000)+(thirdDigit*100)+(fourthDigit*10));
fifthDigitLabel.text = [NSString stringWithFormat:@"%d",fifthDigit];
int sixthDigit = (currentValue *.001) - ((firstDigit *100000)+(secondDigit*10000)+(thirdDigit*1000)+(fourthDigit*100)+(fifthDigit*10));
sixthDigitLabel.text = [NSString stringWithFormat:@"%d",sixthDigit];
int seventhDigit = (currentValue *.01) - ((firstDigit *1000000)+(secondDigit*100000)+(thirdDigit*10000)+(fourthDigit*1000)+(fifthDigit*100)+(sixthDigit*10));
seventhDigitLabel.text = [NSString stringWithFormat:@"%d",seventhDigit];
int eighthDigit = (currentValue *.1) - ((firstDigit *10000000)+(secondDigit*1000000)+(thirdDigit*100000)+(fourthDigit*10000)+(fifthDigit*1000)+(sixthDigit*100)+(seventhDigit*10));
eighthDigitLabel.text = [NSString stringWithFormat:@"%d",eighthDigit];
int ninthDigit = (currentValue *1) - ((firstDigit *100000000)+(secondDigit*10000000)+(thirdDigit*1000000)+(fourthDigit*100000)+(fifthDigit*10000)+(sixthDigit*1000)+(seventhDigit*100)+(eighthDigit*10)+1);
ninthDigitLabel.text = [NSString stringWithFormat:@"%d",ninthDigit];
虽然这可以找到前 7 位数字,但我在找到第 8 位和第 9 位时遇到了问题(它们相互依赖)。这很奇怪,因为当我自己使用第 8 位和第 9 位方程式进行数学运算时,它们起作用了,而且只有当我将它们添加到应用程序时,它们才开始搞砸。