+ Reply to Thread
Results 1 to 4 of 4

if-statement regarding decimals

  1. #1
    Registered User
    Join Date
    05-30-2007
    Posts
    4

    if-statement regarding decimals

    Hello there,
    I’m currently trying to rectify an old if-statement from a program where I want the following to happen:
    If a number in a specified cell is a whole number (like 4), then I want it to do the following calculation:
    h = bunn * 5 + 2 (where "bunn" is my specified value).

    If the number in the specified cell has decimals (like 4.3) then I want this equation to be executed:
    h = bunn * 5 + 1

    If somebody can help me out with this issue I would appreciate it greatly.

  2. #2
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898
    Try

    =bunn*5 +IF(INT(A1)=A1,2,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 oldchippy's Avatar
    Join Date
    02-14-2005
    Location
    Worcester, UK
    MS-Off Ver
    Excel 2007 (Home)
    Posts
    7,097
    Does this work for you?

    =IF(MOD(A1,1)=0,A1*5+2,A1*5+1)
    oldchippy
    -------------


    Blessed are those who can give without remembering and take without forgetting

    If you are happy with the help you have received, please click the <--- STAR icon on the left - Thanks.

    Click here >>> Top Excel links for beginners to Experts

    Forum Rules >>>Please don't forget to read these

  4. #4
    Registered User
    Join Date
    10-01-2007
    Posts
    23
    Quote Originally Posted by Mikaelul
    Hello there,
    I’m currently trying to rectify an old if-statement from a program where I want the following to happen:
    If a number in a specified cell is a whole number (like 4), then I want it to do the following calculation:
    h = bunn * 5 + 2 (where "bunn" is my specified value).

    If the number in the specified cell has decimals (like 4.3) then I want this equation to be executed:
    h = bunn * 5 + 1

    If somebody can help me out with this issue I would appreciate it greatly.
    Does this work if you implement this same idea into your code? Essentially it is converting the decimal of type double to an integer and storing it as a separate variable. If the two variables (original number and new integer) are equal, we have a whole number. However, if they are not equal, the new variable chopped off the decimal when it converted it to an integer. Let me know if this is what you need.

    Please Login or Register  to view this content.

+ 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