+ Reply to Thread
Results 1 to 7 of 7

Double <> Double

  1. #1
    Registered User
    Join Date
    03-20-2009
    Location
    Lithuania
    MS-Off Ver
    Excel 2013
    Posts
    99

    Double <> Double

    Hi,

    I have this code in my userform:
    Please Login or Register  to view this content.
    Watch window shows, that both No3 and No4 have values equalt to -10.8. However, statement "If No3 <> No4" is also shown as true, but it should be false, because both variants have the same value. How could it be?
    Last edited by walduxas; 08-08-2017 at 04:04 AM.

  2. #2
    Valued Forum Contributor quekbc's Avatar
    Join Date
    01-18-2010
    Location
    Sydney, Australia
    MS-Off Ver
    2010, 2013, 2016
    Posts
    1,149

    Re: Double <> Double

    Rounding issues perhaps between what the watch window says and what it actually is?

    Perhaps try printing the number out in full to see - either by populating a cell in Excel or doing a Debug.Print

  3. #3
    Registered User
    Join Date
    03-20-2009
    Location
    Lithuania
    MS-Off Ver
    Excel 2013
    Posts
    99

    Re: Double <> Double

    "Me.Controls("Label" & 9 & "_" & i).Caption" is equal to "-10.8".
    "Me.Controls("Label" & 5 & "_" & i).Caption" is equal to "4.8".
    "Me.Controls("Label" & 7 & "_" & i).Caption" is equal to "2.25".

    Print screens are attached.
    UF1.jpg
    UF2.jpg

  4. #4
    Valued Forum Contributor quekbc's Avatar
    Join Date
    01-18-2010
    Location
    Sydney, Australia
    MS-Off Ver
    2010, 2013, 2016
    Posts
    1,149

    Re: Double <> Double

    Very curious indeed. My suspicion is with how Excel deals with floating point precision when it comes to decimals (for more info http://www.cpearson.com/excel/rounding.htm).

    A simple test like this fails as well
    Please Login or Register  to view this content.
    Best option is to perhaps round it to say, 6 decimal places?

  5. #5
    Registered User
    Join Date
    03-20-2009
    Location
    Lithuania
    MS-Off Ver
    Excel 2013
    Posts
    99

    Re: Double <> Double

    Another interesting test, performed in Immediate window:
    Please Login or Register  to view this content.
    Solved the issue with rounding to 2 decimal places.

  6. #6
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Double <> Double

    Not relevant here but inadevertently storing a value as text can cause similar problems

    Please Login or Register  to view this content.
    Result
    z = 10.8 , x = 10.8 , True
    q = 10.8 , x = 10.8 , False
    q = 10.8 , z = 10.8 , False

    amend only this line (which only changes the variable "type" for "q")
    Please Login or Register  to view this content.

    Result now =
    z = 10.8 , x = 10.8 , True
    q = 10.8 , x = 10.8 , True
    q = 10.8 , z = 10.8 , True
    Last edited by kev_; 08-08-2017 at 04:36 AM.
    Click *Add Reputation to thank those who helped you. Ask if anything is not clear

  7. #7
    Registered User
    Join Date
    08-08-2014
    Location
    Lancaster, PA
    MS-Off Ver
    2016 (windows & mac)
    Posts
    94

    Re: Double <> Double

    generally comparing doubles for equivalence is not good thing to do due to the way computers handle floating point maths.

    this CPearson post has some good info relative to excel.

    if you really want to get into the weeds then this is another good page

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Double click cell - copy data to new sheet - create a list from double clicking
    By kakky in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 05-04-2015, 11:14 PM
  2. [SOLVED] Add 1 to target on double click, add 0.5 on shift + double click
    By MarmaladeLover in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-26-2015, 06:59 AM
  3. [SOLVED] Before double click event with if statements (Double clicking blank cell stops bdc firing)
    By camdenpars in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 06-27-2014, 09:03 AM
  4. Changing cell properties with double click, then revert with another double click
    By mweber2525 in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 03-01-2014, 01:40 PM
  5. Copy double-clicked cell to next empty row in different sheet with each double-click
    By erhathaway in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 08-25-2013, 12:06 AM
  6. Double stack and double line graph
    By Karen311261 in forum Excel General
    Replies: 5
    Last Post: 10-06-2010, 11:58 AM
  7. Double Locks ? Double Trouble
    By JXBlack in forum Excel General
    Replies: 1
    Last Post: 10-04-2009, 03:33 AM

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