This is the legacy 4D documentation web site. Documentations are progressively being moved to developer.4d.com

Home

 
4D v19.8
collection.sum( )

collection.sum( ) 


 

collection.sum ( {propertyPath} ) -> Function result 
Parameter Type   Description
propertyPath  Text in Object property path to be used for calculation
Function result  Real in Sum of collection values

The collection.sum( ) method returns the sum for all values in the collection instance.

Only numerical elements are taken into account for the calculation (other element types are ignored).

If the collection contains objects, pass the propertyPath parameter to indicate the object property to take into account.

collection.sum( ) returns 0 if:

  • the collection is empty,
  • the collection does not contain numerical elements,
  • propertyPath is not found in the collection.

 C_COLLECTION($col)
 $col:=New collection(10;20;"Monday";True;2)
 $vsum:=$col.sum() //32

 C_COLLECTION($col)
 $col:=New collection
 $col.push(New object("name";"Smith";"salary";10000))
 $col.push(New object("name";"Wesson";"salary";50000))
 $col.push(New object("name";"Gross";"salary";10500,5))
 $vSum:=$col.sum("salary") //$vSum=70500,5

 
PROPERTIES 

Product: 4D
Theme: Collections
Number: 805260

This command can be run in preemptive processes

 
PAGE CONTENTS 
 
HISTORY 

Created: 4D v16 R6

 
ARTICLE USAGE

4D Language Reference ( 4D v19)
4D Language Reference ( 4D v19.1)
4D Language Reference ( 4D v19.4)
4D Language Reference ( 4D v19.5)
4D Language Reference ( 4D v19.6)
4D Language Reference ( 4D v19.7)
4D Language Reference ( 4D v19.8)