+ Reply to Thread
Results 1 to 14 of 14

Numbers have too many decimals

  1. #1
    Registered User
    Join Date
    02-08-2009
    Location
    Strathalbyn, South Australia
    MS-Off Ver
    Excel 2003
    Posts
    6

    Numbers have too many decimals

    A spreadsheet created by exporting from QuickBooks as a .IIF file is opened in Excel 2003.

    A macro multiplies a cell value and returns 1.77999997138977 rather than 1.78. The 1.78 is required for importing back into Quickbooks.

    Part of the code is:
    Please Login or Register  to view this content.
    the tempNum in the IF line is 1.78, but ActiveCell.Value is not. So, though 1.78 appears in the spreadsheet cell, clicking on the cell displays 1.77999997138977 in the Formula Bar.

    I am aware of the binomial floating point thingy, but can anyone solve this or find a workaround?
    Last edited by stev49; 02-08-2009 at 06:56 AM.

  2. #2
    Valued Forum Contributor mudraker's Avatar
    Join Date
    11-10-2003
    Location
    Melbourne, Australia
    Posts
    3,983

    Re: 1.77999997138977 not 1.78

    Welcome to Exceltip forum

    Please take a couple of minutes and read all the Forum Rules


    Your post does not comply with Rule 1 of our Forum RULES. Your post title should accurately and concisely describe your problem, not your anticipated solution. Use terms appropriate to a Google search. Poor thread titles, like Please Help, Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will be addressed according to the OP's experience in the forum: If you have less than 10 posts, expect (and respond to) a request to change your thread title. If you have 10 or more posts, expect your post to be locked, so you can start a new thread with an appropriate title.
    To change a Title on your post, click EDIT then Go Advanced and change your title, if 2 days have passed ask a moderator to do it for you.
    Please Read Forum Rules Before Posting
    Wrap VBA code by selecting the code and clicking the # icon or Read This
    How To Cross Post politely

    Top Excel links for beginners to Experts

    If you are pleased with a member's answer then use the Scales icon to rate it
    If my reply has assisted or failed to assist you I welcome your Feedback.

  3. #3
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Numbers have too many decimals

    I can't see what the problem is your code takes the activecell's value & multiplies it by a multiplier. Then formats to two decimal places, finally, finally removing the formula which results in a two decimal number. The code could be nater
    Please Login or Register  to view this content.
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  4. #4
    Registered User
    Join Date
    02-08-2009
    Location
    Strathalbyn, South Australia
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: Numbers have too many decimals

    Quote Originally Posted by royUK View Post
    I can't see what the problem is your code takes the activecell's value & multiplies it by a multiplier. Then formats to two decimal places, finally, finally removing the formula which results in a two decimal number. The code could be nater
    Please Login or Register  to view this content.
    Nope - still doesn't work. I copied and pasted and checked - still get a long decimal pasted into the cellon the SS.

    To prove it for yourself, step through the code using F8. When you have executed the IF line then hovering with your mouse over tempNum gives a different value to Active.Cell.Value.

    Very frustrating.

    Yes, the code could be simpler but I teach programming to 15yo's so I have to break everything down into steps. Also, the Input-Process-Output model really helps their understanding of what is going on.

    The above problem though is from my wife's accounting job (so I can't upload the file for people to check).

  5. #5
    Registered User
    Join Date
    02-08-2009
    Location
    Strathalbyn, South Australia
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: Numbers have too many decimals

    Ooops

    Double post.

  6. #6
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Numbers have too many decimals

    I created a dummy sheet placed a decimal value in a cell, ran the code & the result as a two decimal number, even stepping through the code Post your workbook

  7. #7
    Registered User
    Join Date
    02-08-2009
    Location
    Strathalbyn, South Australia
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: Numbers have too many decimals

    Zipped using WinRAR.

    Load Personal.xls first - contains the macro.
    Then load Copy-Doctored.IIF
    CTRL-M to run macro. Remove stop-point first if you want
    Enter business name eg Netafim
    Enter multiplier eg 1.33
    Check eg M46, a Netafim product, by placing the cursor in the cell and looking at the formula bar.
    M46, which originally contained 65 will appear to contain 86.45 but, according to the formula bar, contains 86.4499969482421. Ditto with the rest of the monies across the row.

    And thanks for your interest - very much appreciated.
    Attached Files Attached Files

  8. #8
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Numbers have too many decimals

    What is your code actually supposed to do? You don't need to select cells & you seem to just loop to random row 6000.

    When I follow your instructions it doesn't change the cell's value at all

  9. #9
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Numbers have too many decimals

    I think this is doing what you want, without all the selecting and so will be much faster
    Please Login or Register  to view this content.

  10. #10
    Registered User
    Join Date
    02-08-2009
    Location
    Strathalbyn, South Australia
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: Numbers have too many decimals

    Thanks RoyUK. I will check it out tonight - morning here and I'm at work.

  11. #11
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Numbers have too many decimals

    Post back & let me know if it works OK

  12. #12
    Registered User
    Join Date
    02-08-2009
    Location
    Strathalbyn, South Australia
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: Numbers have too many decimals

    Quote Originally Posted by royUK View Post
    Post back & let me know if it works OK
    Been having another go today.

    The problem is solved in the sense that QuickBooks truncates the imported numbers to 5 dp.

    But I'm still quite curious about the problem, so I shall return to it from time to time.

    Some points:
    1. after 2 hours today i have an Object required (Error 424) error so am calling it quits for a few days.
    2. i have learnt from some of your code methods, especially the LastRw and Cells tricks, and have included them in my main program.
    3. it didin't like Dim Left(tempNum, 5) As Single so i just used tempNum. Tried is as a string but didn't work
    4. Working on:
    Left(tempNum, 5) = Round((Cells(countRows, 13).Value * multiplier), 2)
    If Left(tempNum, 5) <> 0 Then Cells(countRows, 13).Value = Left(Left(tempNum, 5), 5)
    AND
    remming out the On Error Resume Next is interesting, which is where I am at the moment. weird things happening, so ran out of time for today and need to get back to what i should really be doing.

    Very much appreciated mate.

    PS why are you using the 5 in left(tempNum,5)??

  13. #13
    Valued Forum Contributor mudraker's Avatar
    Join Date
    11-10-2003
    Location
    Melbourne, Australia
    Posts
    3,983

    Re: Numbers have too many decimals

    Re point 3
    Dim Left(tempNum, 5) As Single
    Dim is the 1st part of declaring a variable
    Left(tempNum, 5) is to get the 1st 5 characters from the tempNum variable - It is not a variable name which is what you probaly require.
    You would also need to do something with the extract 5 characters
    As Single is the variable type - You may need a larger variable type like Double


    example
    Please Login or Register  to view this content.
    In Roy's code I do not see anywhere that tempNum is populated which will give an error when trying to Left(tempNum, 5)

  14. #14
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Numbers have too many decimals

    I can't remember exactly, but it was possibly in the code that I edited. I think the relevant variable I declared as a double. It might just be that I copied a pasted without editing correctly.

+ 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