Xcode CGFloat to NSInteger conversion

There are two ways to Convert From CGFloat to NSInteger.
Solution one.
Convert CGFloat to NSString, then take integer value.
1 2 | CGFloat foo = 540.0f; NSInteger bar = [[ NSString stringWithFormat: @"%.2f" ,foo] integerValue]; |
Solution two.
Just take Integer value.
1 2 | CGFloat foo = 540.0f; NSInteger bar = ( int )foo; |
Additional useful Infomartion
1 2 3 4 | 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 |