iOS objective-C: using modulo on a float to get "inches" from Feet -


i trying make simple objective-c height converter. input (float) variable of feet, , want convert (int) feet , (float) inches:

float totalheight = 5.122222; float myfeet = (int) totalheight; //returns 5 feet float myinches = (totalheight % 12)*12; //should return 0.1222ft, becomes 1.46in 

however, keep getting error xcode, , realized modulo operator works (int) , (long). can please recommend alternative method? thanks!

even modulo works float, use :

fmod()

you can use way too...

float totalheight = 5.122222; float myfeet = (int) totalheight; //returns 5 feet float myinches = fmodf(totalheight, myfeet); nslog(@"%f",myinches); 

Comments