Pages

September 21, 2013

NSString to CGFloat conversion with custom decimal separator

Useful method for converting a NSString text to CGFloat value.


/** Returns a float from a string with arbitrary decimal separator.

 @param str String representing a floating number.
 @param separator String of decimal separator.
 @return Returns the float value.
 @see stringFromFloat:usingSeparatorForDecimal:

 */
+ (CGFloat)floatFromString:(NSString *)str withSeparatorForDecimal:(NSString *)separator {
    return [[str stringByReplacingOccurrencesOfString:separator withString:@"."] floatValue];
}



Download the ready-for-use source file (.m) of NSString to CGFloat conversion with custom decimal separator

No comments:

Post a Comment