Extracting Integer and Decimal portion from a number in different cells – Part 1 - KING OF EXCEL

# Extracting Integer and Decimal portion from a number in different cells – Part 1

When it comes to information then most of the time its about numbers and often numbers come with decimals i.e. numbers that are written as:
• 9.82
• 0.9856486
• 1021587.986244
But what if we are only interested in decimal portion (fractional part) of the number or we are interested in the integer (integral part) of the number? Separating the two is not that easy as you might thing. I happened to have faced this situation and on my way to solve this problem to get best possible result I tested different possibilities and comes to know what works and what does not work.

Method 1: Using Text to column
First solution that springs to mind is using text to column feature of Excel. And I did exactly this.
Step 1: Select a range
Step 2: In the ribbon above go to Data tab > and in data tools group click Text to columns button
Step 3: A dialogue box will open. Make sure that delimited radio button is selected and click Next button
Step 4: Uncheck any option select and select other check box. In the input box type in decimal by hittin a dot key on the keyboard. Click Next
Step 5: Click finish to complete the process
So we have a decimal number split up in two columns with integral part in one and decimal part in the other. Great right?
Well if the intention is to split the numbers up then its job well done. But how about if we need to use the decimal part? This is where this solution fails. Because even the decimal portion is appearing like an integer where in fact its not. But we do have one solution to have a decimal as well.

## Using paste special with hidden powers – Method 1 continued

Step 1: Now I know that all of my numbers were at two decimal places so I will put 100 in any vacant cell and copy that cell with Ctrl+C
Step 2: Now select the column that contains the decimal parts of original numbers and hit Alt+Ctrl+V this invokes Paste-special command and will bring up a dialogue box.
Step 3: Under operations select divide option and click OK button.
And done! All the numbers are back in their actual nature. And now we can easily use them for calculation without worrying much.

Although the Paste special solution has worked quite well. But it does have its limitation. In the above example luckily I had numbers with decimal portions of equal length i.e. two decimal places and dividing all of them by 100 I achieved the results. But what if every number is of different length? In that case paste special solution will fail too.
In my case I had fractional part of varying length so that didn’t worked for numbers that had decimal portion other than two decimal places.

## Method 2: Entering the reign of Excel functions

Excel comes with numerous functions that help us achieve the desired results. So after Excel features found their limits I headed to its power-point i.e. functions.
Related to my tast I had following options that I considered out of numerous:
• INT and MOD
• FIND/SEARCH, LEN, MID/LEFT/RIGHT
• FLOOR
• TRUNC

## Combo 1: INT and MOD function

INT function helps get the integral part of the number whereas MOD function help us extract the decimal part. And it is super easy to apply too.
You need two columns to use these two functions. One with INT and the other with MOD.
Step 1: With the data in column A, in cell B1 type Integral part and in cell C1 type Decimal part. In cell B2 put this formula:
=INT(A2)
And in cell C2 put this formula:
=MOD(A2)
Select cell B2 and C2 and drag the fill handle down to the range where you want integral and decimal parts to be separated or simply double click to have the same formula down the same column for the whole range.
Amazing results. No issues with decimals. No issues with integers. Awesome.
Everything went OK until the number turned negative and with it all the work is upside down too.
So one lesson learnt. If the numbers are positive you can use combination of these two formulae. If the number is negative then you are out of luck.

## Combo 2: Using FIND/SEARCH with LEFT/RIGHT/MID

Lets complicate things a little bit now as our simple techniques are not giving us solution to the scope we intend.
After failing with INT and MOD I went to good old FIND function. The idea is to get the integral part and decimal part by finding the decimal. Once the decimal is found I will strip either left side of decimal or right side of decimal to get the desired portion of the original number.
Getting the integral part
To fetch the integral part of the number I used this formula:
=LEFT(A1,FIND(“.”,A1)-1)
Above I used LEFT with FIND function. With left function we can extract specific number of characters out of cell contents. Therefore, we simply have to give the reference of cell from which to extract which in our case is A1 and we also have to tell the number of characters from LEFT side of the cell. For this parameter instead of giving a hard number I used FIND function. FIND function tells at what position particular content is placed. I asked FIND function to tell the position of decimal that came out 3. So the resultant of FIND function will be 3 which will ultimately tell LEFT function to extract 3 characters starting from left.
But having three will include decimal too. Excel counts decimal as a character as well. To get rid of decimal I put -1 that will make the result 3-1=2 therefore only numbers excluding decimal will be reported by Excel.
To get the decimal part I used this formula:
=MID(A1,FIND(“.”,A1),LEN(A1))
Here you see three functions working together. MID works on a same patter as LEFT but instead if starts extracting from the middle instead of left. However, as it starts from the middle it requires additional parameter as compared to LEFT in which we have to tell how many characters does a content has. To get this number I used LEN. LEN function returns the number of characters in a cell.
Although the LEFT/RIGHT/MID combination with FIND has worked good but it surely has complicated the situation unnecessarily. I will be looking at more convenient methods in Part 2 of this tutorial explaining other possibilities in this regard.
#evba #etipfree #eama #kingexcel