Performs one or more calculations and adds the results. Returns the sum of it all.
Syntax
Code: Select all
calc([term=<clipboard>], [separator="<crlf>"], [flags], [precision=0])
term: One or more numbers or mathematical terms (separated by separator).
Numbers can be positive or negative, fractional or integer.
Defaults to the current clipboard contents.
separator: Separator between calculations.
Defaults to CRLF (standard Windows linefeed).
flags: (bit field)
1 = Formats the returned number acc. to system defaults
(thousand separators, decimal digits).
2 = Formats the returned number with X decimal digits (where X
is specified in the "precision" argument) and no thousand
separators. The format is independent of regional settings.
precision: Number of digits after the decimal point in the returned number.
Defaults to 2.
Can also be negative. A negative precision refers to
rounded digits before the decimal point.
Code: Select all
echo calc("16.1, 3.89, -20", ","); //-0.01
echo calc("123456.789, 1", ",", 0); //123457,789
echo calc("123456.789, 1", ",", 1); //123.457,79 (German locale)
echo calc("123456.789, 1", ",", 2); //123457,79
echo calc("123456.789, 1", ",", 2, 3); //123457,789
echo calc("123456.789, 1", ",", 2, -3); //123000
// In clipboard: | 77 * 125 |
// | 142 * 135 |
// | 157 * 145 |
echo calc(); // 51560
echo calc(2:=1); // 51.560,00 (German locale)
// In clipboard: | 19.99 |
// | dog |
// | |
// | 1/100 |
echo calc(); // 20 (the dog and the empty line are ignored)
echo calc(2:=1); // 20,00 (German locale)
- The terms are calculated, then all results are added to the total result.
- Any leading or trailing spaces, or empty line are ignored.
- Anything that's neither a term nor a number is silently ignored (in theory; in reality some invalid terms pass the test and you might get a "Dubious Syntax" warning then).
- If you live in region where "," is the decimal separator you can use both "," and "." as decimal separators.
- Introduced: v19.40.0101 - 2018-11-27 16:31