[英]NSNumberFormatter Problem
在我的应用程序中,我必须在事件人员之间共享金额,例如,我有3个人,例如RAM,RAJ,RAGHU,如果RAM在活动中投入的金额为10.00,那么我10.00/3=3.333333
3个人划分为10.00/3=3.333333
,然后,
RAJ必须支付RAM ------------- 3.33
RAGHU必须支付RAM ------- 3.33
他从事件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];
为什么不从10中减去RAM的份额? 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.