Unable to convert String to Long in Velocity Template

3.2k Views Asked by At

I am trying to convert a string value to long. As the number is too big for integer. $Integer.parseInt normally works but in this case, it saying the number is too big.

I tried $Long.parseLong($variable) or $variable.longValue()

The line of code is:

#set ($cos= $Long.parseLong($kbpsValue) / 1000)

When i print the value of $cos, it just prints the variable name. The value of kbpsValue is 4451400000.

1

There are 1 best solutions below

0
On BEST ANSWER

$Long doesn't exist in VTL. And String.toLong() doesn't exist in Java. If the conversion tool is available in the context, you can try:

$conv.toNumber($variable)

which relies upon the NumberFormat.parse(String) method.