加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

objective-c – 将货币格式化字符串转换为普通字符串

发布时间:2020-12-16 07:27:18 所属栏目:百科 来源:网络整理
导读:我有一个带有货币符号和货币格式的字符串… 我想将它转换为普通字符串.. 我的代码是这样的…… -(NSString *)removeCurrency:(NSString *)str{ NSNumberFormatter *_currencyFormatter = [[NSNumberFormatter alloc] init]; [_currencyFormatter setNumberSt
我有一个带有货币符号和货币格式的字符串…
我想将它转换为普通字符串..

我的代码是这样的……

-(NSString *)removeCurrency:(NSString *)str{


    NSNumberFormatter *_currencyFormatter = [[NSNumberFormatter alloc] init];
    [_currencyFormatter setNumberStyle:NSNumberFormatterCurrencyStyle];
    [_currencyFormatter setNegativeFormat:@"-¤#,##0.00"];

    NSLog(@"n With Currency : %@",str);
    NSLog(@"n Without Currency : %@",[_currencyFormatter numberFromString:str]);

    return [NSString stringWithFormat:@"%@",[_currencyFormatter numberFromString:str]]; 
}

但问题是,当我输入字符串Rs 0.009它返回我不同的值,但与另一个数字,它工作完美…

解决方法

为什么不在将货币格式添加到它之前存储该值.通常,您只在显示之前添加货币格式,而不是存储.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读