suppose I have the following IronPython script:
def Calculate(input):
return input * 1.21
When called from C# with a decimal, this function returns a double:
var python = Python.CreateRuntime();
dynamic engine = python.UseFile("mypythonscript.py")
decimal input = 100m; // input is of type Decimal
// next line throws RuntimeBinderException:
// "cannot implicitly convert double to decimal"
decimal result = engine.Calculate(input);
I seem to have two options:
First, I could cast at the C# side: seems like a no-go as I might loose precision.
decimal result = (decimal)engine.Calculate(input);
Second option is to use System.Decimal in the python script: works, but pollutes the script somewhat...
from System import *
def CalculateVAT(amount):
return amount * Decimal(1.21)
Is there a short-hand notation DLR that the number 1.21 should be interpreted as a Decimal, much like I would use the '1.21m' notation in C#? Or is there any other way to enforce decimal to be used instead of double?