首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >NSNumberFormatter问题

NSNumberFormatter问题
EN

Stack Overflow用户
提问于 2011-09-29 04:42:58
回答 2查看 238关注 0票数 1

在我的应用程序中,我必须在事件人之间共享数量--例如,我有三个人的名字,如RAM、RAJ、RAGHU,如果内存在事件中的数量是10.00,那么我就把它分成三个人,比如10.00/3=3.333333

RAJ必须向RAM支付

RAGHU必须支付RAM -3.33

总之,他从事件中的其他两个人那里得到了6.66,这里缺少了0.1,我该如何解决这个问题,我正在使用NumberStyle:NSNumberFormatterCurrencyStyle,如下所示

代码语言:javascript
复制
NSNumberFormatter *numberFormater = [[NSNumberFormatter alloc] init];
[numberFormater setLocale:[NSLocale currentLocale]];
[numberFormater setNumberStyle:NSNumberFormatterCurrencyStyle];
NSString *str_num = [numberFormater stringFromNumber:[NSNumber numberWithDouble:3.333333]];
[numberFormater release];
EN

回答 2

Stack Overflow用户

发布于 2011-09-29 04:53:46

你为什么不把RAM的份额从10? 10-3.33= 6.67减去。

票数 0
EN

Stack Overflow用户

发布于 2011-09-29 05:07:48

代码语言:javascript
复制
  float invoice= 10.15;
  int num_people = 3; // sample people
  float num_to_add;
  float piece_pie;
  // now just add num_to_add to your invoice then divide by num_people
  num_to_add=num_people*.01;
  invoice=invoice+num_to_add;
  piece_pie = invoice/num_people;
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7592529

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档