Problem with decimals and doubles

Jan 18, 2012 at 4:52 PM


I'm having troubles with a method that manages numbers.

The method is defined as follows (C#): 

public static class GeneralFunctions
     public static decimal MyMethod(decimal a, decimal b)
         decimal result = ...
         return result;

Inside my script, I'm calling:


MyMethod(v, 18)

being v a variable inserted in the script engine as a value of (C#) type decimal.

When I run the script I get an exception of type ArgumentException, whose message is:

Object of type 'System.Double' cannot be converted to type 'System.Decimal


If I switch the method signature to be:

public static object MyMethod(object a, object b)

then I see that a parameter is of type decimal (the v variable in the caller), while the other (the 18 value in the caller) is of type double.

Seems like the engine is not able to perform a conversion from double to decimal.