Overview
What Sum Numbers does
Total the numbers found in selected text. It runs locally and handles the selected text without contacting a service.
| Category | Notes & Productivity |
|---|---|
| Action type | JavaScript |
| Default result | Copy the result |
| Internet | Not required |
Example
Action and outcome
| Action | Outcome |
|---|---|
| Sum NumbersSelected text: Setup 1,250.50 + hosting 49.50 + tax 100 | 1400 |
Workflow
Use Sum Numbers
Follow these steps to total the numbers found in selected text with ActionClip.
- Select the text you want to use.
- Choose Sum Numbers from ActionClip.
- Review the extracted result, then copy it where you need it.
Before you add it
Requirements and privacy
- Before you start: No setup required.
- Your selected text: Runs locally in ActionClip’s JavaScript sandbox. Selected text does not leave your Mac.
Inspect before installing
Action script
The script below is included so you can inspect how the action works before downloading it.
JavaScript definition
function run(selected_text) {
var matches = selected_text.match(/[-+]?(?:\d{1,3}(?:,\d{3})+|\d+)(?:\.\d+)?/g) || [];
if (matches.length === 0) return "No numbers found.";
var precision = 0;
var total = matches.reduce(function (sum, raw) {
var decimal = raw.match(/\.(\d+)$/);
if (decimal) precision = Math.max(precision, decimal[1].length);
return sum + Number(raw.replace(/,/g, ""));
}, 0);
if (!Number.isFinite(total)) return "The selected numbers are too large to total safely.";
return total.toFixed(precision).replace(/\.0+$/, "").replace(/(\.\d*?)0+$/, "$1");
}