Reputation: 199
I am trying to convert to float to int
float flot=2.1456;
char* c [] = {(char *)flot};
ObjLen = sizeof(c)/sizeof(*c);
NSLog(@"ObjLen %d",ObjLen);
but it is showing error Operand of type 'float' cannot be cast to a pointer type
and Converting Char* to back again to float
Upvotes: 0
Views: 1651
Reputation: 2087
I think better way is using sprintf
or snprintf
methods from stdio.h
. sprintf/snprintf
2x faster than @Prince approach.
Upvotes: 0
Reputation: 38239
Firstly convert float to NSString
float flot=2.1456;
NSString *str = [NSString stringWithFormat@"%f",flot];
Use -[NSString UTF8String]: to convert to char *
const char *c = [str UTF8String]
Upvotes: 1