Sum of Digits

Has anyone found a way to calculate the digit sum of a number in Numbers?

Power Mac G5, Mac OS X (10.5.1)

Posted on Dec 20, 2007 7:33 PM

Reply
7 replies

Dec 20, 2007 9:48 PM in response to zefrosnbrick

Here's one method, although it's a little kludgy.

Say your number is in cell B2.

In a series of adjacent cells to the right enter these formulas:

=mid(B2,1,1)
=mid(B2,2,1)
=mid(B2,3,1)
. . .
=mid(B2.x,1) where 'x' is the maximum number of digits for which you're likely to want to find a digit sum.

Assume you've entered these formulas in cells C2 through G2. In cell H2 enter the formula =C2 D2+E2+F2G2. (Sum(C2:G2) results in a '0' for some reason.)

You can hide the interim columns, C through G, to make the table look cleaner.

I have tried combining the MID formulas into a single cell (=mid(B2,1,1) mid(B2,2,1)mid(B2,3,1) ) but it results in an error if the number of digits is less than the number of 'Mid' statements (or to put it another way, if the number of 'Mid' statements is greater than the number or digits.)

There may be a more elegant solution out there, but I'm too tired to look for it.

Good luck,

Terry

Dec 21, 2007 4:48 AM in response to zefrosnbrick

Hello

Assuming that the original number is in column B

Enter this formula in a cell of the same row:

=CNUM(MID($B,1,1))+CNUM(MID($B,2,1))+CNUM(MID($B,3,1))+IF(ISERROR(CNUM(MID($B,4, 1))),0,CNUM(MID($B,4,1)))+IF(ISERROR(CNUM(MID($B,5,1))),0,CNUM(MID($B,5,1)))+IF( ISERROR(CNUM(MID($B,6,1))),0,CNUM(MID($B,6,1)))+IF(ISERROR(CNUM(MID($B,7,1))),0, CNUM(MID($B,7,1)))+IF(ISERROR(CNUM(MID($B,7,1))),0,CNUM(MID($B,8,1)))+IF(ISERROR (CNUM(MID($B,9,1))),0,CNUM(MID($B,9,1)))

It assumes that the number contain at least 3 digits and no more than 9 ones.

It is easy to extand to more digits.
Just paste
+IF(ISERROR(CNUM(MID($B,10,1))),0,CNUM(MID($B,10,1)))
then
+IF(ISERROR(CNUM(MID($B,11,1))),0,CNUM(MID($B,11,1)))
at the very end of the formula.

Yvan KOENIG (from FRANCE vendredi 21 décembre 2007 13:47:46)

Dec 21, 2007 6:44 AM in response to zefrosnbrick

If the input number is in A1, try the following. It will handle numbers of basically any size and length without further modification:

=LEN(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUT E(SUBSTITUTE(SUBSTITUTE(A1 ,1,".") ,2,"..") ,3,"...") ,4,"....") ,5,".....") ,6,"......") ,7,".......") ,8,"........") ,9,"........."))

(Inspiration for this comes from Douglas Hofstadter's discussion of [Typograhical Number Theory|http://en.wikipedia.org/wiki/Typographical NumberTheory], in +Gödel, Escher, Bach: an Eternal Golden Braid+, an excellent but mentally challenging book.)

Dec 21, 2007 8:22 AM in response to KOENIG Yvan

KOENIG Yvan wrote:
As my daughter discovered, you forgot to replace "0" by an empty string 😉



Doh....

For completeness, here is the corrected formula:

=LEN(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUT E(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(A1 ,0,"") ,1,".") ,2,"..") ,3,"...") ,4,"....") ,5,".....") ,6,"......") ,7,".......") ,8,"........") ,9,"........."))

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Sum of Digits

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.