Skip to content
elcapo edited this page Oct 16, 2014 · 3 revisions

sumDigits is an auxiliary function that sums the digits of the number received. For instance, it returns 6 for 123, as long as 1+2+3 = 6.

Usage

/* MySQL */
SELECT sumDigits( 12345 ); /* Returns 15 (= 1+2+3+4+5) */
SELECT sumDigits( 99 ); /* Returns 18 (= 9+9) */
/* JavaScript */
var digits = sumDigits( 12345 ); /* digits = 15 (= 1+2+3+4+5) */
var digits = sumDigits( 99 ); /* digits = 18 (= 9+9) */
/* PHP */
$digits = sumDigits( 12345 ); /* $digits = 15 (= 1+2+3+4+5) */
$digits = sumDigits( 99 ); /* $digits = 18 (= 9+9) */

Return values

  • [int] - Sum, one by one, of the digits of the given string.

Category

This function is part of the NIF, NIE & CIF package.

SEPA validations

  • [International Bank Account Numbers (IBAN)](International Bank Account Numbers (IBAN))

Spanish validations

Helpers

  • [Common functions](Common functions)
Clone this wiki locally