+ Reply to Thread
Results 1 to 15 of 15

Maths using Double type

Hybrid View

  1. #1
    Forum Expert Colin Legg's Avatar
    Join Date
    03-30-2008
    Location
    UK
    MS-Off Ver
    365
    Posts
    1,256

    Re: Maths using Double type

    Hi Steve,

    Ah okay, I see what you mean now with respect to the example you gave in your first post.

    Comparison operators can perform both numeric and string comparisons, but these comparisons can yield different results. Generally speaking, you're best off comparing numbers as numbers rather than numbers as strings. I'll give a different example just to illustrate this -
    Sub testIt()
    
        Const dblNUMBER1 As Double = 5.5
        Const dblNUMBER2 As Double = 100.5
        
        'this returns False because > is performing a numeric comparision
        Debug.Print dblNUMBER1 > dblNUMBER2
        
        'this returns True because > is performing a string comparision
        Debug.Print CStr(dblNUMBER1) > CStr(dblNUMBER2)
    
    End Sub
    So just something to watch out for...
    Hope that helps,

    Colin

    RAD Excel Blog

  2. #2
    Registered User
    Join Date
    09-26-2011
    Location
    Dumfries, Scotland
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: Maths using Double type

    Hi Colin,

    Yes I can see why comparing numerics as strings could be a threat but not when using equals. In the application I am using things are either an exact match or not so I am comfortable in using CStr(myval) = Cstr(testResult).

+ 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