sum - return sum of variable values



<sum $fmt $var [$var ...]>

The sum function sums its $var arguments' values - either arithmetically or via string concatenation. The $fmt argument is a <fmt>-style format string that controls how the values are summed, as well as how each value is processed before summing. If $fmt is a string format code (e.g. "%s"), each $var value is printed to a string with $fmt, and the results string-concatenated for a string (varchar) result. If $fmt is a numeric code (e.g. "%d" or "%f"), each $var value is cast to the type indicated by the code (with all integer types promoted to int64), and the results arithmetically summed, for a numeric result of the same type.

sum returns the arithmetic sum or string concatenation of its $var arguments, depending on the $fmt code.


<$x = 1 2 3>
<sum "%d" $x 4>
<sum "%10s" "one" "two" "three">

The output would be (note spacing):

       one       two     three

The sum function was added Sep. 20 1996. In versions prior to Nov 25 1996, the $fmt argument was ignored when concatenating strings.

The $fmt argument should be appropriate for the values' type (numeric or string).

fmt strfmt

Copyright © Thunderstone Software     Last updated: Dec 10 2018
Copyright © 2019 Thunderstone Software LLC. All rights reserved.