VT_CY and VT_DECIMAL
-
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
-
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
Have you tried using
VariantChangeType
to convert to aBSTR
? 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."
-
Have you tried using
VariantChangeType
to convert to aBSTR
? 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."
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.
-
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.
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).
-
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).
I saw that with my first try. The amount 78.90 became 78.9 - not that nice for display purposes.
-
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.
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
-
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).
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