gpt4 book ai didi

flutter - 如何计算列表中双倍数据的总和?

转载 作者:行者123 更新时间:2023-12-03 03:21:21 26 4
gpt4 key购买 nike

假设 ${d.price} 拥有列表中商品的所有价格( double )。如何使用 ${d.price} 计算价格总和?

最佳答案

您可以使用fold来计算总和 Reference例如:

void main() {
List<int> prices = [10,20,30];
int sum = prices.fold(0, (p, c) => p + c);
print(sum);
}

输出

60

关于flutter - 如何计算列表中双倍数据的总和?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62847535/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com