How to execute C# arithmetic expressions code in Groovy?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

How to execute C# arithmetic expressions code in Groovy?

Richard Heintze
  I know groovy can overload operators. Can I enhance groovy so it can execute the following fragments of C# code?
In case you are not fluent in C#, decimal is like BigDecimal, Single is like Float, Double is same. So in both C# and groovy, 33f means a literal single precision value of 33.

In groovy, if there is no designator, the default is BigDecimal as in 33.0.getClass() returns BigDecimal.
In C# however, it is necessary to say 33m to get a BigDecimal (or decimal in C#).

So here are some sample expressions I would like to execute in groovy:

decimal r1 = (x + y) * (1m - (decimal)(z / 100f)) - s;
Single r2 = n * (Single)z/100f;

This will allow me to keep and maintain one copy of these source code fragments in my relational database for both C# and Groovy.


Thanks
Siegfried