
There are two ways to Convert From CGFloat to NSInteger.
Solution one.
Convert CGFloat to NSString, then take integer value.
[code language="objc"]
CGFloat foo = 540.0f;
NSInteger bar = [[NSString stringWithFormat:@"%.2f",foo] integerValue];
[/code]
Solution two.
Just take Integer value.
[code language="objc"]
CGFloat foo = 540.0f;
NSInteger bar = (int)foo;
[/code]
Additional useful Infomartion
[code language="objc"]
CGFloat foo = 540.4f;
CGFloat bar = ceil(foo);//541.0f round-up
CGFloat bar2 = floor(foo);//540.0f round-down
CGFloat bar3 = round(foo);//540.0f round
[/code]
Conversation
In the margins
0 notes
No comments yet. Be the first to leave a note.