.NET Decimal -> COM -> VT_DECIMAL -> Unknown

wakestarwakestar Member Posts: 207
Hi there

I wrote a .NET assembly which has a COM Interface so I can call it from NAV.

I noticed that .NET decimal type gets marshalled to VT_DECIMAL... but the poor NAV classic client doesn't know what VT_DECIMAL is (VT_UNKNOWN).

According to the help...the NAV type Decimal is mapped to VT_Currency and...
The CURRENCY type in COM is a special data type with a fixed point, which has 15 digits to the left of the point and 4 to the right. You should note that the Decimal type in C/AL does not have a fixed point and can have a total of 18 digits. This could possibly lead to some rounding being performed when a Decimal number is passed to a method that expects a CURRENCY, the server manipulates that number and returns it as a CURRENCY. No matter how many digits the original Decimal had to the right of the decimal point, the returned CURRENCY will have no more than 4 digits.

So my question is:
is there a better way than marshalling the .NET Decimal type to VT_Currency?
Since I'm using my .NET assembly also in the newer versions of NAV with .NET Interop ... I want to keep the decimal datatype in .NET... since that works fine.

Anyone?

Answers

  • archer89archer89 Member Posts: 337
    try float or double data type instead.
    best regards
    Franz Kalchmair, MVP
    Alias: Jonathan Archer

    please like / agree / verify my answer, if it was helpful for you. thx.
    Blog: http://moxie4nav.wordpress.com/
  • wakestarwakestar Member Posts: 207
    Thanks! float seems fine.

    May I ask how you handle DateTime? It seems like the time of datetime is lost when marshalled to VT_DATE
  • archer89archer89 Member Posts: 337
    you could convert the datetime value to double using DateTime.ToOADate.
    follow http://stackoverflow.com/questions/16262007/datetime-tooadate-time-only

    you can then convert the double value back to a datetime value.
    best regards
    Franz Kalchmair, MVP
    Alias: Jonathan Archer

    please like / agree / verify my answer, if it was helpful for you. thx.
    Blog: http://moxie4nav.wordpress.com/
  • krikikriki Member, Moderator Posts: 9,112
    [Topic moved from 'NAV/Navision Classic Client' forum to 'NAV Three Tier' forum]

    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


Sign In or Register to comment.