Splitting a number into integer and decimal portions

Posted on November 22nd, 2010 in Excel Howtos , Learn Excel - 24 comments

Splitting Numbers in to Decimal and Integer Portions using ExcelHere is a quick formula tip to start another awesome week.

Often while working with data, I need to split a number in to integer and decimal portions. Now, there are probably a ton of ways you can do this. But here are two formulas I use quite often and they work well.

Assuming the number is in cell A1,

  • Integer part =INT(A1)
  • Decimal part =MOD(A1,1)

These formulas work whenever my data has only positive numbers (which is the case 90% 0f time). But if I am dealing with a mix of positive and negative numbers, I use,

  • Integer part =INT(A1) +(A1<0)=TRUNC(A1,0) [thanks to Somnath for suggesting this]
  • Decimal part =MOD(A1,SIGN(A1))

What formulas do you use to process numbers?

I use a lot of formulas while working with numbers. But my favorite ones are MOD, INT, SIGN, ABS, RAND and RANDBETWEEN (new in Excel 2007, requires Analysis toolpak in earlier versions).

What about you? What formulas do you use and how do you process your numbers? Please share using comments.

Learn more quick tips & formula examples.

Your email address is safe with us. Our policies

Written by Chandoo
Tags: , , , , , ,
Home: Chandoo.org Main Page
? Doubt: Ask an Excel Question

24 Responses to “Splitting a number into integer and decimal portions”

  1. david says:

    interested to know about this =INT(A1) +(A1<0)

    wat's the purpose of +(A1<0) ?

    i traced it and it gave it as TRUE.

    thanks!

  2. Chandoo says:

    @David: Excel treats TRUE as 1 and FALSE as 0. Since INT(negative number) will give a value 1 less than expected, I want to add 1 to it whenever a number is negative and 0 if the number is positive. So the expression (A1<0) will be TRUE or FALSE based on the sign of A1. Now, if you add this to another number, excel converts the TRUE to 1 and FALSE to 0.

    Hope that makes sense.

  3. sam says:

    Number in A1
    For Integers
    In B1
    =TRUNC(A1,0)
    For Decimal
    In C1
    =A1-B1

  4. Eamon says:

    To split numbers (negative or positive) I use =TRUNC(A1,0) then to get the decimal =A1-A2 assuming =TRUNC(A1,0) is in cell A2.

  5. Eamon says:

    Woops – just saw Sam’s post!

  6. Pedro Wave says:

    Formulas to split positive decimal numbers are used to separate dates into days and hours.

    I like to operate with fractions typed as:
    A1 = 0 5/8
    A2 = 2 1/8
    A3 = A1 + A2 = 2 3/4

  7. Shashi says:

    One of my friends had a requirement to separate X and Y coefficients from a string received from CAD software.
    The string would look like x123.234y234.56.(X will be always in the first place but Y place is not fixed as it would depend on integer and Decimal places of X co-efficient)
    Here is one of the solutions:
    Assuming
    Cell A1 -> x123.234y234.56
    Enter Cells B1-> =FIND(“x”,A1,1) – to find the place of X in the string -(it will be always 1)
    Enter CellsC1 ->=FIND(“y”,A1,1) – find Place of Y (position depends on X Coeff.)
    Enter Cells D1 -> =MID(A1,B1+1,C1-2) – to get X coeff.
    Enter Cells E1 -> =MID(A1,C1+1,LEN(A1)-C1)

    Hope this would be helpful for those who take help of Excel while working on Mechanical design software.

    • Karthik KN says:

      There is a better and easier way :

      Assuming Cell A1 contains : x123.234y234.56

      Then

      =MID(A1,2,FIND(“y”,A1,1)-2) – Would give you the X value
      and
      =MID(A1,FIND(“y”,A1,1)+1,LEN(A1)-FIND(“y”,A1,1)) – Would give you the Y Value

      without much fuss ;-)

  8. Kalyan Chattopadhyay says:

    Chandoo,
    your blog (Splitting a number into integer and decimal portions) on these two formulas helps me a lot to solve a big problem at my office. Really awesome blog. Thanks Chandooo.

    THANKS A LOOOOOOOOOOOOOOT.

    Keep it up.

  9. Prateek says:

    Good, but whts the significance of typing 1(divisior) in case of decimal formula. I typed 2,3…. got the same result….

  10. Chandoo says:

    @Eamon & @Sam: Thanks for the tip on TRUNC(). I did not know about it earlier.

    @Pedro: I use it for splitting days and time as well. Also, do you know you can show fractions in excel with custom format code – # ?/?

    @Shashi..good tip, thanks for sharing.

    @Kalyan: I am so glad you find this tip useful.

    @Prateek: The result for 2, 3 will not be same as 1. Check it with multiple values. the fraction portion of a number is nothing but what remains after you remove nearest multiple of 1. (essentially mod(number,1) )

  11. Somnath says:

    Chandoo,

    Since =INT(A1)+(A1<0) on a whole negative integer (with no decimal parts) E.g: -7.00 will return -6, I think the TRUNC function is more effective.

  12. Raiyan says:

    Hi Chandoo…..Can we apply more than one for formula for a cell or a selected range of cell???If we can then how could we…explain with a simple example.

    Regards
    Raiyan

  13. Pedro Wave says:

    Chandoo, using fraction format “As Hundreds” or custom format – # ?/100, decimal number -12.23 can be represented as -12 23/100.
    This fraction format only split decimal numbers visually, but is awesome to me.

  14. Ayan says:

    Thanks Sam & Emon for trunc

  15. Gaurav Jaswal says:

    float a, c, d=0;
    int c
    while(a!=0)
    {
    c= a*10;
    d= d*10 + c;
    a=a*10 – c;
    }

  16. humphrey says:

    How do I split $84,000 in a 12 month period with july and August having equal amounts? What formula can I use? Thank you.

  17. sophie says:

    thanks, this helped me a lot with my formula!

  18. krish says:

    14-294,5,8,9,11,13-17

    hi ,
    in this number series how to take a total count in excel?

  19. John robinson says:

    Hi Chandoo, I. Need to know what formula to use if I want the decimal values to add up separately ie 47.6+48.5=95.11. Every time the decimal value exceeds 9, it automatically increases the values left of the decimal. I do not want that. Kindly assist.

  20. reza says:

    Hi. Thanks for your post.
    I need an formula to change location of decimal and integer digit in a number in excel, like 21.3 => 3.12.

  21. james says:

    HI
    what about these two areas, a number 92.45 , id like to grab part of the numbers from both sides, cant seem to work out how to combine them, e.g. 92.45 I want .45 to be as 45 ( solved as above in a post ) however what about 245 where the first number and the decimals are only looked at . I don’t want he number 9 . also what about 81.7653 , I want to be able to grab only the last 3 digits of the decimal place, so it looks like 653?

    any help on truncing this correctly would be good , thanks in advance.

Leave a Reply