Integer and Floating-Point Conversions
To effectively develop Objective-C programs, you must understand the rules used for the implicit conversion of floating-point and integer values in Objective-C. Program 4.5 demonstrates some of the simple conversions between numeric data types.
// Basic conversions in Objective-C#import <Foundation/Foundation.h>int main (int argc, char * argv[]){ @autoreleasepool { float f1 = 123.125, f2; int i1, i2 = -150; i1 = f1; // floating to integer conversion NSLog (@"%f assigned to an int produces %i", f1, i1); f1 = i2; // integer to floating conversion NSLog (@"%i assigned to a float produces %f", i2, f1); f1 = i2 / 100; // ...
Get Programming in Objective-C, Sixth Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.