[Solved] Adding two digits together of a two-digit number

Discuss the spreadsheet application

[Solved] Adding two digits together of a two-digit number

Postby Padeen » Sat Aug 08, 2020 9:34 pm

Is there a formula in OOC that I can use either digit separately of a two-digit number for a calculation? Or, how do I return digit x, or y, or z of an xyz number? Return 3 of 235?
Thanks for any help you might offer.
Last edited by MrProgrammer on Sat Aug 15, 2020 4:37 pm, edited 1 time in total.
Reason: Tagged ✓ [Solved]
Open Office 4.1.6 on Windows 10
Padeen
 
Posts: 22
Joined: Fri Nov 23, 2018 9:32 pm

Re: Adding two digits together of a two-digit number

Postby Zizi64 » Sat Aug 08, 2020 9:48 pm

Or, how do I return digit x, or y, or z of an xyz number? Return 3 of 235?


Just a tip:

Convert it to text, then use the Function LEFT(), RIGHT() functions. If you need a numeric value, then convert it again by the function VALUE()

Code: Select all   Expand viewCollapse view
=VALUE(RIGHT(LEFT(TEXT(A1;"000");2);1))
Tibor Kovacs, Hungary; LO6.1.6, 6.2.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-6.4.5;AOO4.1.7
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
User avatar
Zizi64
Volunteer
 
Posts: 9725
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Adding two digits together of a two-digit number

Postby Zizi64 » Sat Aug 08, 2020 10:03 pm

Or you can use the functions INT() and MOD():

Code: Select all   Expand viewCollapse view
= INT(235/100)             -> 2
= MOD(INT(235/10);10)      -> 3
= MOD(235;10)              -> 5
Tibor Kovacs, Hungary; LO6.1.6, 6.2.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-6.4.5;AOO4.1.7
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
User avatar
Zizi64
Volunteer
 
Posts: 9725
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Adding two digits together of a two-digit number

Postby MrProgrammer » Sat Aug 08, 2020 11:15 pm

Padeen wrote:Subject: Adding two digits together of a two-digit number:
Is there a formula in OOC that I can use either digit separately of a two-digit number for a calculation? Or, how do I return digit x, or y, or z of an xyz number?
Adding to Zizi64's second solution with value 235 in cell A2:
=MOD(QUOTIENT($A$2;10^0);10) is 5 (digit position 0)
=MOD(QUOTIENT($A$2;10^1);10) is 3 (digit position 1)
=MOD(QUOTIENT($A$2;10^2);10) is 2 (digit position 2)
=MOD(QUOTIENT($A$2;10^3);10) is 0 (digit position 3)
=MOD(QUOTIENT($A$2;10^4);10) is 0 (digit position 4)
Thus, you can use the same expression structure for each digit position. The exponent (0,1,2,3,4) could also be a cell reference.

More generally, since you have asked about adding digits together:
=SUM(MOD(QUOTIENT($A$2;10^{0;1});10)) is 8 (5+3) (digit positions 0 and 1)
=SUM(MOD(QUOTIENT($A$2;10^{1;2});10)) is 5 (3+2) (digit positions 1 and 2)
=SUM(MOD(QUOTIENT($A$2;10^{0;2});10)) is 7 (5+2) (digit positions 0 and 2)
=SUM(MOD(QUOTIENT($A$2;10^{0;1;2});10)) is 10 (5+3+2) (digit positions 0, 1, and 2)
Each SUM() expression must be entered as an Array formula so type it and and press ⇪⌘Enter (Shift+Command+Enter) on a Mac or Ctrl+Shift+Enter on other platforms; if you press Enter by mistake, use Edit → Delete Contents → Formulas, then try again.

If you need further assistance attach a document demonstrating the situation (remove confidential information then use Post Reply, not Quick Reply, and don't attach a picture instead of the document itself).

If this solved your problem please go to your first post use the Edit button and add [Solved] to the start of the title. You can select the green checkmark icon at the same time.

[Tutorial] Ten concepts that every Calc user should know
Mr. Programmer
AOO 4.1.7 Build 9800 on MacOS 10.14.6.   The locale for any menus or Calc formulas in my posts is English (USA).
User avatar
MrProgrammer
Moderator
 
Posts: 3904
Joined: Fri Jun 04, 2010 7:57 pm
Location: Wisconsin, USA


Return to Calc

Who is online

Users browsing this forum: No registered users and 20 guests