[英]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.