In my grails project, I move all the calculations to Java classes.
Here is the link to the source code (I saved it in Google Docs).
The main goal is to format the current time in a string (in two languages). Examples:
1 day 2 hours 3 seconds 1 2 3
But I have one method:
private static boolean endsWith(final long num, final long part) { if (num / 10 < 1) { return num == part; } else { float val1 = (num - part) / 10; float val2 = (float) Math.floor(val1); return val1 == val2; } }
It checks to see if 'num' ends with 'part'. Examples:
assert endsWith(128, 1) == false assert endsWith(1, 1) == true assert endsWith(34, 4) == true
PS num is the standard long (java.lang.Long) value, and part is greater than 0 and less than or equal to 9 (1..9).
But this code only works fine in groovy classes.
In the java class, I got the following results:
endsWith(7, 7) == true endsWith(23, 3) == false endsWith(23, 1) == true
As I can see from gant magazine - all code compiled by groovyc .
PS2 . I am compiling this code with groovyc and javac to compare the results. Because, if I'm not mistaken, it could be a groovyc mistake. But this is my mistake, I hope :)