+ Reply to Thread
Results 1 to 5 of 5

INT issue

  1. #1
    Registered User
    Join Date
    11-01-2007
    Posts
    8

    INT issue

    So, I'm converting bond prices from a price feed which takes the form ###.@@%
    where # = normal integers
    @@= are @@/32
    and % = 1/8 of 32nds

    Anyway, to my question:

    Say i have 103.215 in cell A1 - that's 103 + 21/32 + 5/256

    So, to convert that, I have the formula in the adjacent cell:
    =INT((A1-INT(JA1))*100)

    I'm taking the approach of breaking out the digits behind the decimal into @@ and % and then converting and then adding them together to get the decimal form. That formula gives me the whole number 21, which i can then convert to 32nds by dividing. Now let's say I have the number 103.21 in Cell A1 - the output of that formula is 20!!!

    The error only happens when there are two digits ONLY behind the decimal.

    How does the INT function work that it makes this silly error? I've also tried TRUNC but that gives me the same output.
    Last edited by bsmith81; 11-01-2007 at 12:09 PM.

  2. #2
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898
    The calculation within the parentheses calculates to 20.09999999994, you just need to round it up.

    Try incorporating the Round() function:

    =INT(ROUND((A1-INT(A1))*100,1))
    Where there is a will there are many ways.

    If you are happy with the results, please add to the contributor's reputation by clicking the reputation icon (star icon) below left corner

    Please also mark the thread as Solved once it is solved. Check the FAQ's to see how.

  3. #3
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    2016
    Posts
    14,675
    This is the result of the way excel calculates using "floating point arithmetic", see here.

    =(A1-INT(A1))*100 probably gives a result something like 20.9999999 then when you take the integer part with INT you get 20 not 21.

    Try using

    =INT(MOD(A1*100,100))

  4. #4
    Registered User
    Join Date
    10-30-2007
    Posts
    51
    This gets it done. If need be, the steps can be combined into a single formula.
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    11-01-2007
    Posts
    8

    Thanks All

    Interesting - Always good to know a bit about how excel calculates stuff.

    Good solutions - thanks for your help!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1