|
SYNOPSIS
<sum $fmt $var [$var ...]>
DESCRIPTION The sum function numerically (floating-point) sums the
$var arguments' values. The result is then cast to the type
implied by the $fmt argument, which is a fmt format
string for one numeric argument. If $fmt is empty,
``%g'' is assumed.
The $fmt format can be any numerical format supported by the
fmt function (p. ). Thus, ``%d'' would
return an integer, truncated if needed; ``%1.2f'' would return
a floating point value with up to 2 decimal places.
If one or more of the values of any of the $var arguments are
non-numeric, the function returns the string concatenation of
the $var values instead. In this case, each value (not the
result) is first formatted with the $fmt argument. If
$fmt is empty, ``%s'' is assumed.
DIAGNOSTICS If all arguments are numeric, sum numerically sums them, and
then formats and casts the result using the $fmt argument. If
any arguments are non-numeric, each argument is formatted with the
$fmt argument, and their string concatenation is returned.
EXAMPLE
<$x = 1 2 3>
<sum "%d" $x 4>
$ret
<sum "%10s" "one" "two" "three">
$ret
The output would be (note spacing):
10
one two three
CAVEATS 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).
SEE ALSO
fmt
Copyright © Thunderstone Software Last updated: Wed Sep 10 11:16:28 EDT 2008
|