How to sum digits in the same cell "calc"

So when i have a number in a cell like “112” i would like to sum all its number so 112 becomes 1+1+2 =4

note i would like to reduce the numbers so that it will reduce to 1 digit, so if i would have something like the number “96” 9+6=15 = 1+5=6

i found a formula that works for small numbers < 10 digits, but i need something that works with large numbers as well > 40

regards…

This seems to me a need best answered by creating a function in the Calc sheet script. I believe you should be able to use LO Basic to avoid enabling JRE (Java Run-time Engine).

In essence, you would pass the formula result to the function as a parameter (the formula would be wrapped in the function). The function would then analyze the parameter to determine the number of digits and the value of each digit. The digits would be summed. This process would be wrapped in a loop so that the result is analyzed and processed until 1-digit reduction is achieved. The final resulting value would be returned to the calling cell.

I hope this helps. Good luck.

Please click the check mark next to the response you believe best answers your question.

For real Integers up to ~14digits*** :

 =IF(MOD(A1;9);MOD(A1;9);9) 

***because calcs 64bit float represententation for every number you need to store larger Numbers as Text, and to prepare the calculation above to split into slices with maximal size of 14 digits. for example:

=VALUE(LEFT(A1;14))
=VALUE(MID(A1;15;14))
…