`Measure-Object Sum`未返回数组的总和。

huangapple go评论65阅读模式
英文:

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

huangapple
  • 本文由 发表于 2023年6月25日 23:49:56
  • 转载请务必保留本文链接:https://go.coder-hub.com/76551230.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定