DelphiBasics
Sum
Function
Return the sum of an array of floating point values Math unit
 function Sum(const Numbers array of Double):Double;
Description
The Sum function returns the sum of the values in the supplied Numbers array of double values.
Related commands
DecDecrement an ordinal variable
IncIncrement an ordinal variable
SqrGives the square of a number
SqrtGives the square root of a number
 Download this web site as a Windows program.




 
Example code : Examples of summing arrays and hard coded values
var
  doubles : array[0..5] of double;

begin
  // Fill up the number array
  doubles[0] :=  25.0;
  doubles[1] := 100.5;
  doubles[2] :=  -4.125;
  doubles[3] :=  75.0;
  doubles[4] := -62.0;
  doubles[5] :=   0.0;

  ShowMessage('Sum of array values = '+FloatToStr(Sum(doubles)));
  ShowMessage('12.3 + 45.6 = '+FloatToStr(Sum([12.3, 45.6])));
end;
Show full unit code
  Sum of array values = 134.375
  12.3 + 45.6 = 57.9
 
Delphi Programming © Neil Moffatt . All rights reserved.  |  Home Page