Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 添加返回nil的NSDecimalNumber_Objective C_Nsdecimalnumber - Fatal编程技术网

Objective c 添加返回nil的NSDecimalNumber

Objective c 添加返回nil的NSDecimalNumber,objective-c,nsdecimalnumber,Objective C,Nsdecimalnumber,我有这个密码 int countCosts = [Costs count]; countCosts = countCosts - 1; NSDecimalNumber* Total = [[NSDecimalNumber alloc] initWithString:[NSString stringWithFormat:@"%f", 0.0]]; NSDecimalNumber *cost = 0; while (countCosts != -1) { cos

我有这个密码

int countCosts = [Costs count];
countCosts = countCosts - 1;
NSDecimalNumber* Total = [[NSDecimalNumber alloc] initWithString:[NSString    stringWithFormat:@"%f", 0.0]];
NSDecimalNumber *cost = 0;
    while (countCosts != -1)
    {
        cost = [Costs objectAtIndex:countCosts];
        Total = [Total decimalNumberByAdding:cost];
        countCosts = countCosts - 1;
        if (countCosts < 0)
            break;
    }
int countCosts=[Costs count];
countCosts=countCosts-1;
NSDecimalNumber*Total=[[NSDecimalNumber alloc]initWithString:[NSString stringWithFormat:@“%f”,0.0]];
NSDecimalNumber*成本=0;
while(countCosts!=-1)
{
成本=[成本对象索引:countCosts];
总计=[总小数位数加总:成本];
countCosts=countCosts-1;
如果(成本<0)
打破
}
成本(数组中有1.10、2.25、3.50个)。
总计应等于成本中所有项目的总计。但等于0

成本
数组中添加所有成本的逻辑有点奇怪。试试这个:

NSDecimalNumber *total = [NSDecimalNumber zero];
for (NSString *cost in Costs) {
    NSDecimalNumber *num = [NSDecimalNumber decimalNumberWithString:cost];
    total = [total decimalNumberByAdding:num];
}

NSLog(@"total = %@", total);

顺便说一句-标准命名约定规定类以大写字母开头,而方法和变量以小写字母开头。

costs
数组中添加所有开销的逻辑有点奇怪。试试这个:

NSDecimalNumber *total = [NSDecimalNumber zero];
for (NSString *cost in Costs) {
    NSDecimalNumber *num = [NSDecimalNumber decimalNumberWithString:cost];
    total = [total decimalNumberByAdding:num];
}

NSLog(@"total = %@", total);

顺便说一句-标准命名约定规定类以大写字母开头,而方法和变量以小写字母开头。

costs
数组中添加所有开销的逻辑有点奇怪。试试这个:

NSDecimalNumber *total = [NSDecimalNumber zero];
for (NSString *cost in Costs) {
    NSDecimalNumber *num = [NSDecimalNumber decimalNumberWithString:cost];
    total = [total decimalNumberByAdding:num];
}

NSLog(@"total = %@", total);

顺便说一句-标准命名约定规定类以大写字母开头,而方法和变量以小写字母开头。

costs
数组中添加所有开销的逻辑有点奇怪。试试这个:

NSDecimalNumber *total = [NSDecimalNumber zero];
for (NSString *cost in Costs) {
    NSDecimalNumber *num = [NSDecimalNumber decimalNumberWithString:cost];
    total = [total decimalNumberByAdding:num];
}

NSLog(@"total = %@", total);


顺便说一句-标准命名约定规定类以大写字母开头,而方法和变量以小写字母开头。

在循环开始之前,什么是
Total
Costs
数组是否包含
NSDecimalNumber
s?总计为0,Costs数组包含plist上的内容。2.60 1.10 1.10 1.10 1.10 2.85 2.85 1.10 1.10 1.10 1.10 1.10 2.85 2.85 1.10 1.10 1.10这将值显示为字符串,而不是数字。在何处将每个字符串转换为
NSDecimalNumber
?循环开始前的
总数是多少?
Costs
数组是否包含
NSDecimalNumber
s?总计为0,Costs数组包含plist上的内容。2.60 1.10 1.10 1.10 1.10 2.85 2.85 1.10 1.10 1.10 1.10 1.10 2.85 2.85 1.10 1.10 1.10这将值显示为字符串,而不是数字。在何处将每个字符串转换为
NSDecimalNumber
?循环开始前的
总数是多少?
Costs
数组是否包含
NSDecimalNumber
s?总计为0,Costs数组包含plist上的内容。2.60 1.10 1.10 1.10 1.10 2.85 2.85 1.10 1.10 1.10 1.10 1.10 2.85 2.85 1.10 1.10 1.10这将值显示为字符串,而不是数字。在何处将每个字符串转换为
NSDecimalNumber
?循环开始前的
总数是多少?
Costs
数组是否包含
NSDecimalNumber
s?总计为0,Costs数组包含plist上的内容。2.60 1.10 1.10 1.10 1.10 2.85 2.85 1.10 1.10 1.10 1.10 1.10 2.85 2.85 1.10 1.10 1.10这将值显示为字符串,而不是数字。您在哪里将每个字符串转换为一个
NSDecimalNumber
?代码工作(某种程度上)总数等于0.000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000201954995630462021096371054384448,而不是它应该的26.10。有什么想法吗?在调试器中运行代码,并在循环的每个迭代中查看
total
cost
。您是否看到任何意外情况?成本是正常的,但总成本会越来越小。您是否确定
成本
数组中的每个值都是
NSDecimalNumber
?成本数组包含plist上的内容。2.60 1.10 1.10 1.10 1.10 2.85 2.10 1.10 1.10 1.10 1.10 2.85 2.85 1.10 1.10 1.10 1.10代码工作(排序)总结果等于0.000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002019549956304021096371054384448,而不是它应该达到的26.10。有什么想法吗?在调试器中运行代码,并在循环的每个迭代中查看
total
cost
。您是否看到任何意外情况?成本是正常的,但总成本会越来越小。您是否确定
成本
数组中的每个值都是
NSDecimalNumber
?成本数组包含plist上的内容。2.60 1.10 1.10 1.10 1.10 2.85 2.10 1.10 1.10 1.10 1.10 2.85 2.85 1.10 1.10 1.10 1.10代码工作(排序)总结果等于0.000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002019549956304021096371054384448,而不是它应该达到的26.10。有什么想法吗?在调试器中运行代码,并在循环的每个迭代中查看
total
cost
。您是否看到任何意外情况?成本是正常的,但总成本会越来越小。您是否确定
成本
数组中的每个值都是
NSDecimalNumber
?成本数组包含plist上的内容。2.60 1.10 1.10 1.10 1.10 2.85 2.10 1.10 1.10 1.10 1.10 2.85 2.85 1.10 1.10 1.10 1.10代码工作(排序)总结果等于0.000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002019549956304021096371054384448,而不是它应该达到的26.10。有什么想法吗?在调试器中运行代码,并在循环的每个迭代中查看
total
cost
。您是否看到任何意外情况?成本是正常的,但总成本会越来越小。您是否确定
成本
数组中的每个值都是
NSDecimalNumber
?成本数组包含plist上的内容。2.60 1.10 1.10 1.10 1.10 2.85 2.85 1.10 1.10 1.10 1.10 1.10 2.85 2.85 1.10 1.10