简体   繁体   English

NSNumberFormatter问题

[英]NSNumberFormatter Problem

IN my App i have to share the amount among the event people for Example i have 3 people names like RAM, RAJ, RAGHU ,if RAM put amount of 10.00 in event than i am dividing the among three people like 10.00/3=3.333333 , Then, 在我的应用程序中,我必须在事件人员之间共享金额,例如,我有3个人,例如RAM,RAJ,RAGHU,如果RAM在活动中投入的金额为10.00,那么我10.00/3=3.333333 3个人划分为10.00/3=3.333333 ,然后,

RAJ has to pay to RAM-------------3.33 RAJ必须支付RAM ------------- 3.33
RAGHU has to pay to RAM -------3.33 RAGHU必须支付RAM ------- 3.33

over all he getting From other 2 people in the event 6.66 here 0.1 missing how can i solve this problem i am using NumberStyle:NSNumberFormatterCurrencyStyle like below 他从事件2的其他2个人那里得到的所有结果都在这里6.缺少0.1我如何解决此问题,我正在使用NumberStyle:NSNumberFormatterCurrencyStyle,如下所示

NSNumberFormatter *numberFormater = [[NSNumberFormatter alloc] init];
[numberFormater setLocale:[NSLocale currentLocale]];
[numberFormater setNumberStyle:NSNumberFormatterCurrencyStyle];
NSString *str_num = [numberFormater stringFromNumber:[NSNumber numberWithDouble:3.333333]];
[numberFormater release];

Why don't you subtract RAM's share from 10? 为什么不从10中减去RAM的份额? 10 - 3.33 = 6.67. 10-3.33 = 6.67。

  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;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM