I am having an issue with using a float in a UILabel.
float doubleNum;
floatNum = 10 / 20;
cashLabel.text = [[NSString alloc] initWithFormat:@"%f", floatNum];
If I use “floatNum = 10 / 10;” it correctly returns “1.000000000”, however, if I put in “floatNum = 10 / 20” it returns “0.0000000”. I have tried about everything I know and it does not work. I know it’s a dumb mistake, but I can’t figure it out.
Happy Holidays. 🙂
You need to cast one of the integer’s to a float.
Try replacing the divisional line with:
and you should get the correct answer.
Or if possible just use floats in your division:
should also work