开发者

How to convert NSString value @"3.45" into float?

How to convert NSString value @"3.45" into float. 3.45

float fCost = [[NSDecimalNumber decimalNu开发者_StackOverflow社区mberWithString:@"3.45"]floatValue] ;


NSString *val = @"3.45";
float fCost = [val floatValue];


float number = [string floatValue];


NSString's: - (float)floatValue;

For example:

NSString *str = @"3.45";
float f = [str floatValue];


Reading your comment to Marek's answer it looks like your string actually = @"$3.45"

To convert that to a float use:

NSNumberFormatter * formatter = [[[NSNumberFormatter alloc] init] autorelease];
formatter.numberStyle = NSNumberFormatterCurrencyStyle;
formatter.currencyCode = @"USD";

float value = [[formatter numberFromString: @"$3.45"] floatValue];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜