[xwiki-users] Strangeness with numbers...
Why can't I do something like: #set($tRule = "") #set($idx = $tRule.indexOf(',')) $idx ## Outputs -1 $idx+1 ## Outputs -1+1 I've tried using the $number tool but it doesn't work, if I do: $number.format($idx) It outputs $number.format($idx). What am I missing? .:. Kevin -- View this message in context: http://n2.nabble.com/Strangeness-with-numbers...-tp2168613p2168613.html Sent from the XWiki- Users mailing list archive at Nabble.com.
Hi, On Jan 16, 2009, at 4:05 PM, Kevin_C wrote:
Why can't I do something like:
#set($tRule = "") #set($idx = $tRule.indexOf(','))
$idx ## Outputs -1
$idx+1 ## Outputs -1+1
I've tried using the $number tool but it doesn't work, if I do:
$number.format($idx)
It outputs $number.format($idx).
See http://platform.xwiki.org/xwiki/bin/view/DevGuide/Scripting (it's $numbertool)
What am I missing?
.:. Kevin
Thanks -Vincent http://xwiki.com http://xwiki.org http://massol.net
Vincent Massol wrote:
Hi,
On Jan 16, 2009, at 4:05 PM, Kevin_C wrote:
Why can't I do something like:
#set($tRule = "") #set($idx = $tRule.indexOf(','))
$idx ## Outputs -1
$idx+1 ## Outputs -1+1
Natural, remember velocity is a template language. #set($idx = $idx + 1)
I've tried using the $number tool but it doesn't work, if I do:
$number.format($idx)
It outputs $number.format($idx).
See http://platform.xwiki.org/xwiki/bin/view/DevGuide/Scripting
(it's $numbertool)
What am I missing?
.:. Kevin
Thanks -Vincent http://xwiki.com http://xwiki.org http://massol.net
_______________________________________________ users mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/users
Yah, that makes sense.. Still trying to get the hang of all this. Thanks again!! .:. Kevin -- View this message in context: http://n2.nabble.com/Strangeness-with-numbers...-tp2168613p2170342.html Sent from the XWiki- Users mailing list archive at Nabble.com.
Ugh, typo. Sorry. I ended up using $util.add($num, 1).. Thanks! .:. Kevin -- View this message in context: http://n2.nabble.com/Strangeness-with-numbers...-tp2168613p2170347.html Sent from the XWiki- Users mailing list archive at Nabble.com.
On Jan 16, 2009, at 9:03 PM, Kevin_C wrote:
Ugh, typo. Sorry. I ended up using $util.add($num, 1)..
Don't use that one it's deprecated and will be removed soon. Look at your logs you should see the deprecation warning appearing. Use numbertool instead. Thanks -Vincent http://xwiki.com http://xwiki.org http://massol.net
OK, then how do I add two numbers using the numbertool? Here's what I have: $numbertool.toNumber($tRule.indexOf('.')) This displays a number as a string just fine. Now, I need to add 1 to it. I've tried: $numbertool.toNumber($tRule.indexOf('.')).intValue()+1 ## displays 1+1 $numbertool.toNumber($tRule.indexOf('.')+1) ## crashes $numbertool.format($numbertool.toNumber($tRule.indexOf('.')).intValue()+1) ## crashes $numbertool.toNumber($numbertool.toNumber($tRule.indexOf('.'))+1) ## crashes I know this is a scripting language and all but it doesn't seem that something this simple should be so hard to do. Does velocity not have the concept of a number?!? Thanks! .:. Kevin -- View this message in context: http://n2.nabble.com/Strangeness-with-numbers...-tp2168613p2186603.html Sent from the XWiki- Users mailing list archive at Nabble.com.
nm, I found $mathtool which allows addition of 2 objects. Thanks! .:. Kevin Kevin_C wrote:
OK, then how do I add two numbers using the numbertool? Here's what I have:
$numbertool.toNumber($tRule.indexOf('.'))
This displays a number as a string just fine. Now, I need to add 1 to it. I've tried:
$numbertool.toNumber($tRule.indexOf('.')).intValue()+1 ## displays 1+1
$numbertool.toNumber($tRule.indexOf('.')+1) ## crashes
$numbertool.format($numbertool.toNumber($tRule.indexOf('.')).intValue()+1) ## crashes
$numbertool.toNumber($numbertool.toNumber($tRule.indexOf('.'))+1) ## crashes
I know this is a scripting language and all but it doesn't seem that something this simple should be so hard to do. Does velocity not have the concept of a number?!?
Thanks! .:. Kevin
-- View this message in context: http://n2.nabble.com/Strangeness-with-numbers...-tp2168613p2186617.html Sent from the XWiki- Users mailing list archive at Nabble.com.
participants (3)
-
Kevin_C -
Marius Dumitru Florea -
Vincent Massol