+ Reply to Thread
Results 1 to 4 of 4

Rounding errors

  1. #1
    Registered User
    Join Date
    07-07-2010
    Location
    Sweden
    MS-Off Ver
    Excel 2003
    Posts
    3

    Rounding errors

    I've created a small VBA code to calculate the percentage using two cells.
    The relevant code is simple. Similar to something like this:
    Please Login or Register  to view this content.
    Now, when I enter "1000" into cell "val1" and "123" into cell "val2", the result should be 12,3 %, but instead it says "12". I've already tried increasing the number of decimals in the cell and it didn't work.Please help. Thanks

    Edit: The wierd part is that it works fine for another cell, just not the one I want the result to be in.
    Edit2: If you need the entire code, please let me know.
    Last edited by Divran; 07-07-2010 at 05:26 AM.

  2. #2
    Forum Expert sweep's Avatar
    Join Date
    04-03-2007
    Location
    Great Sankey, Warrington, UK
    MS-Off Ver
    2003 / 2007 / 2010 / 2016 / 365
    Posts
    3,444

    Re: Rounding errors

    Hi,

    This code works fine for me. There must be some formatting issue with the result cell, or the value is truncated elsewhere in your code.
    Rule 1: Never merge cells
    Rule 2: See rule 1

    "Tomorrow I'm going to be famous. All I need is a tennis racket and a hat".

  3. #3
    Registered User
    Join Date
    07-07-2010
    Location
    Sweden
    MS-Off Ver
    Excel 2003
    Posts
    3

    Re: Rounding errors

    Alright, I've found out the problem is somewhere in my code because I can see the "12" change to "12,3" for 1 milisecond then change to "12".

    Sooo... here's the entire code:
    Please Login or Register  to view this content.
    And here's a screenshot to show you my problem:
    \1
    As you can see, the testing cell to the left shows the correct value (12,3) while the main cell shows only 12,00.
    Last edited by Divran; 07-07-2010 at 04:20 AM.

  4. #4
    Registered User
    Join Date
    07-07-2010
    Location
    Sweden
    MS-Off Ver
    Excel 2003
    Posts
    3

    Re: Rounding errors

    Wohoo! I found a fix.

    I added the variables "old_" for current, increment, incrementpercent and newsalary respectively, and edited the writing code so that it looks like
    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