英文:
Measure-object Sum not returning Sum of array
问题
如果我查询一个列,我会得到一个数字列表作为返回。如果我将它放入 Measure-Object 中,Sum 不正确?
如何最有效地对这个数字列表求和?
$array.'Profit'
返回...
- 0.000
- 0.000
- 0.000
- 2387.500
- 1610
$array.'Profit' | measure-object -property length -minimum -maximum -sum -average
返回一个数字列表...
- Count : 5
- Average : 5.4
- Sum : 27
- Maximum : 8
- Minimum : 4
- Property : Length
Sum 似乎不正确?
我在这里漏掉了什么?
感谢您的时间。
英文:
I have an array that If I query a column, I get a list of numbers in return. If I place into Measure-Object, the Sum is not correct?
What is most efficient way to Sum this list of numbers?
$array.'Profit'
Returns...
- 0.000
- 0.000
- 0.000
- 2387.500
- 1610
$array.'Profit' | measure-object -property length -minimum -maximum -sum -average
Returns a list of numbers...
- Count : 5
- Average : 5.4
- Sum : 27
- Maximum : 8
- Minimum : 4
- Property : Length
Which the Sum doesn't add up?
What am I missing here?
Thank you for your time
答案1
得分: 2
如果我理解您的示例正确,`Profit` 是每个数组元素中的单一属性,去掉对长度的引用(`-property length`):
$array = 1.1, 2.1, 3.1 | % { [pscustomobject]@{profit = $_} }
$array.profit | measure -minimum -maximum -sum -average
Count : 3
Average : 2.1
Sum : 6.3
Maximum : 3.1
Minimum : 1.1
Property :
或者
$array | measure -property profit -minimum -maximum -sum -average
Count : 3
Average : 2.1
Sum : 6.3
Maximum : 3.1
Minimum : 1.1
Property : profit
最小值、最大值、总和和平均值都是 `[double]` 类型的实例。
$array | measure -property profit -minimum -maximum -sum -average | % sum |
% gettype
IsPublic IsSerial Name BaseType
True True Double System.ValueType
英文:
If I take your example right, Profit
being a single property in each array element, taking off the reference to length (-property length
):
$array = 1.1, 2.1, 3.1 | % { [pscustomobject]@{profit = $_} }
$array.profit | measure -minimum -maximum -sum -average
Count : 3
Average : 2.1
Sum : 6.3
Maximum : 3.1
Minimum : 1.1
Property :
Or
$array | measure -property profit -minimum -maximum -sum -average
Count : 3
Average : 2.1
Sum : 6.3
Maximum : 3.1
Minimum : 1.1
Property : profit
Minimum, maximum, sum, and average end up as instances of type [double]
.
$array | measure -property profit -minimum -maximum -sum -average | % sum |
% gettype
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True True Double System.ValueType
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论