Difference between CDec and CDbl

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • James

    #1

    Difference between CDec and CDbl

    Can anyone explain the difference between these two conversion
    functions? Thanks

  • Josip Medved

    #2
    Re: Difference between CDec and CDbl

    One converts to Decimal, other to Double?
    Can anyone explain the difference between these two conversion
    functions? Thanks
    --
    Greetings,
    Josip Medved
    A personal website dedicated to technology, software development, and practical tools.


    Comment

    • Herfried K. Wagner [MVP]

      #3
      Re: Difference between CDec and CDbl

      "James" <jamesburkett@g mail.comschrieb :
      Can anyone explain the difference between these two conversion
      functions?
      They convert to different types.

      --
      M S Herfried K. Wagner
      M V P <URL:http://dotnet.mvps.org/>
      V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

      Comment

      • James

        #4
        Re: Difference between CDec and CDbl

        i meant the technical differences... what does one read that the other
        cannot? Thanks.


        Herfried K. Wagner [MVP] wrote:
        "James" <jamesburkett@g mail.comschrieb :
        Can anyone explain the difference between these two conversion
        functions?
        >
        They convert to different types.
        >
        --
        M S Herfried K. Wagner
        M V P <URL:http://dotnet.mvps.org/>
        V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

        Comment

        • Josip Medved

          #5
          Re: Difference between CDec and CDbl

          i meant the technical differences... what does one read that the other
          cannot? Thanks.
          Since both decimal as double are numeric types, I doubt that there is
          any difference, as in from what they can convert, but there is big
          difference in types to which they convert to.

          --
          Greetings,
          Josip Medved
          A personal website dedicated to technology, software development, and practical tools.


          Comment

          • Jay B. Harlow [MVP - Outlook]

            #6
            Re: Difference between CDec and CDbl

            In addition to the other comments:

            CDec returns a Decimal value.

            CDbl returns Double value.

            As you may know TypeOf Decimal IsNot TypeOf Double. Decimal is a base 10
            floating point number, while Double is a base 2 floating point number. They
            have different precisions & ranges.

            If you have Option Strict On (you do have Option Strict On don't you)
            attempting to use CDbl and assign it to a Decimal will cause a compile
            error. While attempting to use CDec and assign it to a Double will cause an
            implicit conversion from Decimal to Double (read it will work, but you
            really did CDbl(CDec(?)).

            --
            Hope this helps
            Jay B. Harlow [MVP - Outlook]
            ..NET Application Architect, Enthusiast, & Evangelist
            T.S. Bradley - http://www.tsbradley.net


            "James" <jamesburkett@g mail.comwrote in message
            news:1159115402 .663951.3770@i4 2g2000cwa.googl egroups.com...
            Can anyone explain the difference between these two conversion
            functions? Thanks
            >

            Comment

            • James

              #7
              Re: Difference between CDec and CDbl

              As you may know TypeOf Decimal IsNot TypeOf Double. Decimal is a base 10
              floating point number, while Double is a base 2 floating point number. They
              have different precisions & ranges.

              Can you explain this a little more? I work well with examples and I
              don't really understand what you're saying here. Thanks!

              Comment

              • Jay B. Harlow [MVP - Outlook]

                #8
                Re: Difference between CDec and CDbl

                Binary floating point & .NET:


                Decimal floating point in .NET:


                The short of it is a Decimal number can exactly represent base 10 (ergo
                Decimal) numbers. Double (and Single) cannot exactly represent base 10
                numbers, as they store the numbers as base 2.

                --
                Hope this helps
                Jay B. Harlow [MVP - Outlook]
                ..NET Application Architect, Enthusiast, & Evangelist
                T.S. Bradley - http://www.tsbradley.net


                "James" <jamesburkett@g mail.comwrote in message
                news:1159124973 .838383.288750@ d34g2000cwd.goo glegroups.com.. .
                >As you may know TypeOf Decimal IsNot TypeOf Double. Decimal is a base 10
                >floating point number, while Double is a base 2 floating point number.
                >They
                >have different precisions & ranges.
                >
                >
                Can you explain this a little more? I work well with examples and I
                don't really understand what you're saying here. Thanks!
                >

                Comment

                Working...