Pages

July 23, 2013

Float with comma as decimal separator

Apple systems (iPhone, iPad, iPod and Mac OS X) use the dot as decimal separator while some other platforms (like Windows) use the comma.
This convenient method might help you.


/** Returns a string representing a float with comma instead of dot as decimal separator.

 @param val Original floating point number.
 @return Returns string representing the number with comma as separator.

 */
+ (NSString *)floatWithComma:(CGFloat)val {
    return [[NSString stringWithFormat:@"%.2f", val] stringByReplacingOccurrencesOfString:@"." withString:@","];
}



Download the ready-for-use source file (.m) of Float with comma as decimal separator

No comments:

Post a Comment