Notes & Productivity

Sum Numbers

Total the numbers found in selected text.

OfficialOn-device

Download action

What Sum Numbers does

Total the numbers found in selected text. It runs locally and handles the selected text without contacting a service.

CategoryNotes & Productivity
Action typeJavaScript
Default resultCopy the result
InternetNot required

Action and outcome

Sum Numbers example
ActionOutcome
Sum NumbersSelected text: Setup 1,250.50 + hosting 49.50 + tax 1001400

Use Sum Numbers

Follow these steps to total the numbers found in selected text with ActionClip.

  1. Select the text you want to use.
  2. Choose Sum Numbers from ActionClip.
  3. Review the extracted result, then copy it where you need 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.

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");
}