Floating-point math
Christopher Schultz <[email protected]>
| Newsgroups | gmane.comp.jakarta.velocity.user |
|---|---|
| Message-ID | <[email protected]> |
All, I seem to recall that in one of the (semi-)recent releases, Velocity started supporting floating-point values for mathematical operators (+, -, *, /) as well as comparisons (<, >, <=, >=, ==), but I can't find anything in the documentation that suggests that this is the case. A simple test run against Velocity 1.7 works as I expect: Here is some math: #set($fourAndAHalf = 4.5) $fourAndAHalf ($fourAndAHalf.class.name) #set($halfThat = $fourAndAHalf / 2) $halfThat ($halfThat.class.name) #if($fourAndAHalf > $halfThat) works #else confused #end That is, the output of this script is: " Here is some math: 4.5 (java.lang.Double) 2.25 (java.lang.Double) works " So, it appears that floating-point math is supported. When attempting to run the same template under Velocity 1.4, I get this exception: Exception in thread "main" org.apache.velocity.exception.ParseErrorException: Lexical error: org.apache.velocity.runtime.parser.TokenMgrError: Lexical error at line 2, column 24. Encountered: "5" (53), after : "." at org.apache.velocity.app.VelocityEngine.evaluate(VelocityEngine.java:286) at VelocityDriver.main(VelocityDriver.java:70) It seems clear that Velocity 1.4 does not support floating-point math but that Velocity 1.7 does. Is it documented anywhere that 1.7 (or 1.6?) supports floating-point math directly in the templates? I have an old project that uses Velocity-Tools' MathTool to do all kinds of stuff and I'd like to remove all that for clarity, but I need to be reasonably confident that I can do that -- at least to a certain degree (e.g. simple math works, but certain operators don't support floats). Thanks, -chris
signature.asc
(application/pgp-signature, 307 B)
-----BEGIN PGP SIGNATURE----- Version: GnuPG/MacGPG2 v2.0.17 (Darwin) Comment: GPGTools - http://gpgtools.org Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iEYEARECAAYFAlAqmA0ACgkQ9CaO5/Lv0PCgMwCfV02DeNnLmp5R6WN0I1yJWgzY HIIAn2ciUABl0Omsrz2fRzghWwBeQ/Lb =+ZfF -----END PGP SIGNATURE-----