groovy-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Richard Heintze <>
Subject How to execute C# arithmetic expressions code in Groovy?
Date Mon, 06 Mar 2017 19:05:13 GMT
  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.

View raw message