velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From apa...@recks.org
Subject Re: String to int
Date Thu, 06 Jul 2006 14:32:15 GMT
Use the Java Integer class as a Tool.

#set( $Integer = 1 )
#set( $myInt = $Integer.valueOf( $myNumericalString ) )
# The valueOf(...) may take a second parameter "radix"
# other cool method is the toHexString()

You can do the same for Long and other Number subclasses:
#set( $Long = $Integer.longValue() )##
## doubleValue()
## floatValue()
## shortValue()
## byteValue()

Note that velocity will always return the Object form instead
of the primitive class.

Look in the ApiDoc for more of this...
#set( $String = "1" )
#set( $Char = $String.charAt(0) )

Cheers,
Christoph

Serge Matveenko wrote:
> Hello!
> It might be that my question has been asked many times but i couldn't
> find the answer:(
> 
> I need to convert 'String' object containing representation of the
> number to 'int' value using only Velocity features.
> Now i have only one solution: just write simple converting macros that
> will compare each character of the string with all 10 digits.
> Could somebody make it better?
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Mime
View raw message