在我的應用程序中,接受金額值(float)並保存它。在金額字段中,用戶可以在小數點後輸入任意數量的數字。但是,當我讀取並保存時,它應該只有小數點後的兩位數。這個場景適用於我的代碼。但問題是,如果用戶輸入值2.468,它將被保存爲2.47。但如果用戶輸入是2.245,在這種情況下,我需要保存爲2.25,但它只能保存爲2.24。十進制值四捨五入到ios中的下一個更高值
和我的代碼是
AmountValue = [NSString stringWithFormat:@"%f",[AmountTxt1.text floatValue]];
float Rate_int = [AmountValue floatValue];
NSNumberFormatter *currencyFormatter = [[NSNumberFormatter alloc] init];
[currencyFormatter setNumberStyle:NSNumberFormatterCurrencyStyle];
NSString *str1 = [NSString stringWithFormat:@"%@",[currencyFormatter stringFromNumber:[NSNumber numberWithFloat:Rate_int]]];
TotalAmtTxt.text = str1;
? – Rajneesh071