如何格式化货币字符串以浮动值? [英] How to format a currency string to float value?

查看:43
本文介绍了如何格式化货币字符串以浮动值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在得到像这样的字符串$ 2,000.00.现在,我想将此字符串更改为浮点值.如何将此字符串转换为float.实际上,此字符串($ 2,000.00)来自使用货币格式化程序格式化数字.但是现在我想将此字符串更改为浮点值.

Iam getting the string like this $2,000.00. Now i want to change this string to float value. How to convert this string as float.Actually this string($2,000.00)is coming from formatting number with currency formatter. But now i want to change this string to float value..

请为此指导任何人.

预先感谢.

推荐答案

考虑字符串.

    NSString *str = @"$2,000.00";

创建数字格式器.

    NSNumberFormatter *nf = [[NSNumberFormatter alloc] init];

重要的事情" .

The "important thing".

    [nf setNumberStyle:NSNumberFormatterCurrencyStyle];

这就是您想要的".

"Here is what you want".

    NSNumber *number = [nf numberFromString:str];
    float f = [number floatValue];

当然,请释放数字格式化程序.

And of course, release the number formatter.

    [nf release];

这篇关于如何格式化货币字符串以浮动值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆