ios - 如何从 NSMutableArray 中获取浮点数的总和 [英] ios - How get the total sum of float from a NSMutableArray

查看:12
本文介绍了ios - 如何从 NSMutableArray 中获取浮点数的总和的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个包含很多 NSString 和 float 的 NSMutableArray

I created a NSMutableArray which contains a lot of NSString and float

DataOrder *addClient = [[DataOrder alloc ] initWithName:[[DataOrder instance]product] price:[[DataOrder instance]price] taille:[[DataOrder instance]taille] suplement:[[DataOrder instance]suplement]];    
[[[ArrayBuying instance] tableau]addObject:addClient];

我在我的数组[[ArrayBuying instance] tableau]"中添加对象

I add the object in my array "[[ArrayBuying instance] tableau]"

如何获得浮点变量的总和?

How can I get the total sum of the float variables ?

谢谢

推荐答案

这样的事情会起作用:

float total = 0;
for (DataOrder *client in [[ArrayBuying instance] tableau]) {
    total += client.price;
}

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

我只是猜测您的 DataOrder 类具有 price 属性.使用你真正拥有的.

I'm just guessing that your DataOrder class has a price property. Use what you really have.

这篇关于ios - 如何从 NSMutableArray 中获取浮点数的总和的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆