NSDecimalNumber *no1 = [NSDecimalNumber decimalNumberWithString:[totalPotFund stringByReplacingOccurrencesOfString:@"," withString:@"."]];//consider totalPotFund = 301
NSLog(@"Total Bank Fund: %@", totalPotFund);
NSDecimalNumber *no2 = [NSDecimalNumber decimalNumberWithString:[MinimumFund stringByReplacingOccurrencesOfString:@"," withString:@"."]];//consider MinimumFund = 1000
NSLog(@"Debet: %@", MinimumFund);
NSDecimalNumber *result = [no1 decimalNumberBySubtracting:no2];//301 - 1000 = -699
NSLog(@"Result = Total Bank Fund - Debet: %@ - %@ = %@", totalPotFund, MinimumFund, result);
NSDecimalNumber *no3 = [NSDecimalNumber decimalNumberWithString:[payAmt.text stringByReplacingOccurrencesOfString:@"," withString:@"."]];//consider payAmt = 12
NSLog(@"Amount to be paid: %@", payAmt.text);
NSComparisonResult res = [result compare:no3]; //-699 compare 12: -699 < 12
NSLog(@"Compare Resultant Amount with CheckOut Amount: %@ compare %@", result, no3);//
if(res == NSOrderedAscending)
{
Do Something
}
else
{
Do The Other Thing
}
Привет всем, проблема, с которой я сталкиваюсь, заключается в том, что, хотя -699 меньше 12, он все равно входит в условие «if (res == NSOrderedAscending)», а не в условие «else».Забавно, что так и должно быть.У меня нет примера кода как такового для сравнения 2 NSDecimal чисел с NSComparisonResult и отправки сравниваемого результата в NSOrderedAscending или NSOrderedDescending или NSOrderedSame.
Спасибо в ожидании.