Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. VT_CY and VT_DECIMAL

VT_CY and VT_DECIMAL

Scheduled Pinned Locked Moved C / C++ / MFC
question
7 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Rome Singh
    wrote on last edited by
    #1

    I'm trying to get a CString representation of _variant_t type VT_CY and VT_DECIMAL. Does anyone know of any classes/code out there that accomplishes this? RS

    M 1 Reply Last reply
    0
    • R Rome Singh

      I'm trying to get a CString representation of _variant_t type VT_CY and VT_DECIMAL. Does anyone know of any classes/code out there that accomplishes this? RS

      M Offline
      M Offline
      Mike Dimmick
      wrote on last edited by
      #2

      Have you tried using VariantChangeType to convert to a BSTR? I'll admit it's not very controllable! VT_CY doesn't look too bad: "A currency number is stored as 64-bit (8-byte), two's complement integer, scaled by 10,000 to give a fixed-point number with 15 digits to the left of the decimal point and 4 digits to the right." You can therefore work it out as follows:

      __int64 unitPart = vt.cyVal / 10000;
      UINT fracPart = vt.cyVal % 10000;
      CString strValue;
      strValue.Format( _T( "%I64d.%u" ), unitPart, fracPart );

      Unfortunately, I can't find any documentation for VT_DECIMAL that indicates which bits do what. The document I referenced above ('VARIANT and VARIANTARG' in the Automation section of the Platform SDK) says only "Decimal variables are stored as 96-bit (12-byte) unsigned integers scaled by a variable power of 10. VT_DECIMAL uses the entire 16 bytes of the Variant."

      R 1 Reply Last reply
      0
      • M Mike Dimmick

        Have you tried using VariantChangeType to convert to a BSTR? I'll admit it's not very controllable! VT_CY doesn't look too bad: "A currency number is stored as 64-bit (8-byte), two's complement integer, scaled by 10,000 to give a fixed-point number with 15 digits to the left of the decimal point and 4 digits to the right." You can therefore work it out as follows:

        __int64 unitPart = vt.cyVal / 10000;
        UINT fracPart = vt.cyVal % 10000;
        CString strValue;
        strValue.Format( _T( "%I64d.%u" ), unitPart, fracPart );

        Unfortunately, I can't find any documentation for VT_DECIMAL that indicates which bits do what. The document I referenced above ('VARIANT and VARIANTARG' in the Automation section of the Platform SDK) says only "Decimal variables are stored as 96-bit (12-byte) unsigned integers scaled by a variable power of 10. VT_DECIMAL uses the entire 16 bytes of the Variant."

        R Offline
        R Offline
        Rome Singh
        wrote on last edited by
        #3

        No I didn't try VariantChangeType - didn't come across it. I was using itoa, ltoa, ultoa and _gcvt (float,double). I will test it out though. You say that it's not controllable. What problems have you encountered? Thanks for the currency snippet above. If I run into any anomolies with VariantChangeType I'll revert back to itoa, ltoa... and you currency code.

        M R 2 Replies Last reply
        0
        • R Rome Singh

          No I didn't try VariantChangeType - didn't come across it. I was using itoa, ltoa, ultoa and _gcvt (float,double). I will test it out though. You say that it's not controllable. What problems have you encountered? Thanks for the currency snippet above. If I run into any anomolies with VariantChangeType I'll revert back to itoa, ltoa... and you currency code.

          M Offline
          M Offline
          Mike Dimmick
          wrote on last edited by
          #4

          When I say 'not controllable', I mean that there's no way to specify how many digits you're going to get (for example, after a decimal point).

          R 2 Replies Last reply
          0
          • M Mike Dimmick

            When I say 'not controllable', I mean that there's no way to specify how many digits you're going to get (for example, after a decimal point).

            R Offline
            R Offline
            Rome Singh
            wrote on last edited by
            #5

            I saw that with my first try. The amount 78.90 became 78.9 - not that nice for display purposes.

            1 Reply Last reply
            0
            • R Rome Singh

              No I didn't try VariantChangeType - didn't come across it. I was using itoa, ltoa, ultoa and _gcvt (float,double). I will test it out though. You say that it's not controllable. What problems have you encountered? Thanks for the currency snippet above. If I run into any anomolies with VariantChangeType I'll revert back to itoa, ltoa... and you currency code.

              R Offline
              R Offline
              Rome Singh
              wrote on last edited by
              #6

              It seems that I can use _variant_t vt; COleCurrency oleCur(vt); CString strCur = oleCur.Format(); This will work for a date string as well COleDateTime oleDT(vt); CString strDT = oleDT.Format(); I have some testing to do. I also found the DECIMAL conversion in Carlos Antollini's CADORecordset double val = vtFld.decVal.Lo32; val *= (vtFld.decVal.sign == 128)? -1 : 1; val /= pow(10, vtFld.decVal.scale); str = DblToStr(val); // also define in his class Thanks, RS

              1 Reply Last reply
              0
              • M Mike Dimmick

                When I say 'not controllable', I mean that there's no way to specify how many digits you're going to get (for example, after a decimal point).

                R Offline
                R Offline
                Rome Singh
                wrote on last edited by
                #7

                I sent this to myself by accident. ---------------- It seems that I can use _variant_t vt; COleCurrency oleCur(vt); CString strCur = oleCur.Format(); This will work for a date string as well COleDateTime oleDT(vt); CString strDT = oleDT.Format(); I have some testing to do. I also found the DECIMAL conversion in Carlos Antollini's CADORecordset double val = vtFld.decVal.Lo32; val *= (vtFld.decVal.sign == 128)? -1 : 1; val /= pow(10, vtFld.decVal.scale); str = DblToStr(val); // also define in his class Thanks, RS

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups