Toolbox-XToolbox-X

Sum Digits

Calculates the sum of all digits in a given number, ignoring the sign.

sumDigits

The sumDigits function calculates the sum of all digits in a given number or numeric string, ignoring the negative sign.

Function Signature

function sumDigits(num: Numeric): number

Parameters

  • num (Numeric): The number (or numeric string) whose digits will be summed.

Return Value

  • number: The sum of all digits in the number.

Example Usage

playground.ts

Notes

  • Uses Math.abs internally to ignore the sign of negative numbers.
  • Non-digit characters (except decimals) are ignored during parsing.

Last updated: Sun, Jun 14, 2026 07:06:16AM (UTC)

On this page