You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Raman Jee <ra...@yahoo.com> on 2004/01/21 08:50:42 UTC

Conversion Problem.

Hi,
How type conversion handled in VTL.
Is it possible to convert from Sting to Integer. ??

Regards
Raman Jee Mishra

__________________________________
Do you Yahoo!?
Yahoo! Hotjobs: Enter the "Signing Bonus" Sweepstakes
http://hotjobs.sweepstakes.yahoo.com/signingbonus

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


Re: Conversion Problem.

Posted by Christoph Reck <ap...@recks.org>.
Simply do something like:

#set( $int = 1 )
#set( $string = "123" )
#set( $myInt = $int.valueOf($string) )
A string converted to integer: $myInt

See more on the JDK ApiDocs, e.g. at:
http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Integer.html#valueOf(java.lang.String)

You can use any public method of your context values (which are java class instances).

Cheers,
Christoph

Raman Jee wrote:
> Hi,
> How type conversion handled in VTL.
> Is it possible to convert from Sting to Integer. ??
> 
> Regards
> Raman Jee Mishra
> 
> __________________________________
> Do you Yahoo!?
> Yahoo! Hotjobs: Enter the "Signing Bonus" Sweepstakes
> http://hotjobs.sweepstakes.yahoo.com/signingbonus
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
> 
> 
> 

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


Re: Conversion Problem.

Posted by Nathan Bubna <na...@esha.com>.
Will Glass-Husain said:
> surely you're joking.  Velocity's [comparison operators are] pretty strict 
> about types, actually.  Try
> comparing a String to an  integer, or a String to a StringBuffer.  It just
> silently fails.

true, with a slight adjustment.  :)

> I've a tool in the context to do this kind of conversion
> 
> $Lib.integer
> 
> with method overloading to take a String, double, or Object.

sounds like what the MathTool does :)
also, we have a NumberTool now that can handle i18n of numbers.

Nathan Bubna
nathan@esha.com

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


Re: Conversion Problem.

Posted by Mike Kienenberger <mk...@alaska.net>.
Will Glass-Husain <wg...@forio.com> wrote:
> ...or create a tool with a special conversion method

Or, as Nathan mentioned, use the NumberFormatTool.toNumber() methods.

-Mike

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


Re: Conversion Problem.

Posted by Will Glass-Husain <wg...@forio.com>.
It's all a matter of interpretation, I guess.  More specifically, Velocity
defines literals as Java classes (Integer / String) and follows all (well,
most) Java rules regarding comparison and equality with the literals and
context objects.

Anyway, Raman, you can either use Integer methods (like Christopher
suggested) such as valueOf and toString, or create a tool with a special
conversion method

Best,
WILL

----- Original Message ----- 
From: "Geir Magnusson Jr" <ge...@4quarters.com>
To: "Velocity Users List" <ve...@jakarta.apache.org>
Sent: Wednesday, January 21, 2004 9:13 AM
Subject: Re: Conversion Problem.


>
> On Jan 21, 2004, at 10:08 AM, Will Glass-Husain wrote:
>
> > surely you're joking.  Velocity's pretty strict about types, actually.
> >  Try
> > comparing a String to an  integer, or a String to a StringBuffer.  It
> > just
> > silently fails.
>
> No, I'm not joking.  There is no notion of 'type'.  It doesn't do
> conversions.  it doesn't cast. etc.
>
> >
> > I've a tool in the context to do this kind of conversion
> >
> > $Lib.integer
> >
> > with method overloading to take a String, double, or Object.
> >
> > WILL
> >
> > ----- Original Message -----
> > From: "Geir Magnusson Jr" <ge...@4quarters.com>
> > To: "Velocity Users List" <ve...@jakarta.apache.org>
> > Sent: Wednesday, January 21, 2004 4:31 AM
> > Subject: Re: Conversion Problem.
> >
> >
> >>
> >> On Jan 21, 2004, at 2:50 AM, Raman Jee wrote:
> >>
> >>> Hi,
> >>> How type conversion handled in VTL.
> >>> Is it possible to convert from Sting to Integer. ??
> >>
> >> There is no notion of 'type', really, but to give an smarter answer
> >> than that, we'd need to see an example of what you are trying to do.
> >>
> >> geir
> >>
> >>>
> >>> Regards
> >>> Raman Jee Mishra
> >>>
> >>> __________________________________
> >>> Do you Yahoo!?
> >>> Yahoo! Hotjobs: Enter the "Signing Bonus" Sweepstakes
> >>> http://hotjobs.sweepstakes.yahoo.com/signingbonus
> >>>
> >>> ---------------------------------------------------------------------
> >>> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> >>> For additional commands, e-mail:
> >>> velocity-user-help@jakarta.apache.org
> >>>
> >>>
> >> -- 
> >> Geir Magnusson Jr                                   203-247-1713(m)
> >> geir@4quarters.com
> >>
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> >> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
> >>
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: velocity-user-help@jakarta.apache.org
> >
> >
> -- 
> Geir Magnusson Jr                                   203-247-1713(m)
> geir@4quarters.com
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
>


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


Re: Conversion Problem.

Posted by Geir Magnusson Jr <ge...@4quarters.com>.
On Jan 21, 2004, at 10:08 AM, Will Glass-Husain wrote:

> surely you're joking.  Velocity's pretty strict about types, actually. 
>  Try
> comparing a String to an  integer, or a String to a StringBuffer.  It 
> just
> silently fails.

No, I'm not joking.  There is no notion of 'type'.  It doesn't do 
conversions.  it doesn't cast. etc.

>
> I've a tool in the context to do this kind of conversion
>
> $Lib.integer
>
> with method overloading to take a String, double, or Object.
>
> WILL
>
> ----- Original Message -----
> From: "Geir Magnusson Jr" <ge...@4quarters.com>
> To: "Velocity Users List" <ve...@jakarta.apache.org>
> Sent: Wednesday, January 21, 2004 4:31 AM
> Subject: Re: Conversion Problem.
>
>
>>
>> On Jan 21, 2004, at 2:50 AM, Raman Jee wrote:
>>
>>> Hi,
>>> How type conversion handled in VTL.
>>> Is it possible to convert from Sting to Integer. ??
>>
>> There is no notion of 'type', really, but to give an smarter answer
>> than that, we'd need to see an example of what you are trying to do.
>>
>> geir
>>
>>>
>>> Regards
>>> Raman Jee Mishra
>>>
>>> __________________________________
>>> Do you Yahoo!?
>>> Yahoo! Hotjobs: Enter the "Signing Bonus" Sweepstakes
>>> http://hotjobs.sweepstakes.yahoo.com/signingbonus
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
>>> For additional commands, e-mail: 
>>> velocity-user-help@jakarta.apache.org
>>>
>>>
>> -- 
>> Geir Magnusson Jr                                   203-247-1713(m)
>> geir@4quarters.com
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
>
>
-- 
Geir Magnusson Jr                                   203-247-1713(m)
geir@4quarters.com


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


Re: Conversion Problem.

Posted by Will Glass-Husain <wg...@forio.com>.
surely you're joking.  Velocity's pretty strict about types, actually.  Try
comparing a String to an  integer, or a String to a StringBuffer.  It just
silently fails.

I've a tool in the context to do this kind of conversion

$Lib.integer

with method overloading to take a String, double, or Object.

WILL

----- Original Message ----- 
From: "Geir Magnusson Jr" <ge...@4quarters.com>
To: "Velocity Users List" <ve...@jakarta.apache.org>
Sent: Wednesday, January 21, 2004 4:31 AM
Subject: Re: Conversion Problem.


>
> On Jan 21, 2004, at 2:50 AM, Raman Jee wrote:
>
> > Hi,
> > How type conversion handled in VTL.
> > Is it possible to convert from Sting to Integer. ??
>
> There is no notion of 'type', really, but to give an smarter answer
> than that, we'd need to see an example of what you are trying to do.
>
> geir
>
> >
> > Regards
> > Raman Jee Mishra
> >
> > __________________________________
> > Do you Yahoo!?
> > Yahoo! Hotjobs: Enter the "Signing Bonus" Sweepstakes
> > http://hotjobs.sweepstakes.yahoo.com/signingbonus
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: velocity-user-help@jakarta.apache.org
> >
> >
> -- 
> Geir Magnusson Jr                                   203-247-1713(m)
> geir@4quarters.com
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
>


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


Re: Conversion Problem.

Posted by Geir Magnusson Jr <ge...@4quarters.com>.
On Jan 21, 2004, at 2:50 AM, Raman Jee wrote:

> Hi,
> How type conversion handled in VTL.
> Is it possible to convert from Sting to Integer. ??

There is no notion of 'type', really, but to give an smarter answer 
than that, we'd need to see an example of what you are trying to do.

geir

>
> Regards
> Raman Jee Mishra
>
> __________________________________
> Do you Yahoo!?
> Yahoo! Hotjobs: Enter the "Signing Bonus" Sweepstakes
> http://hotjobs.sweepstakes.yahoo.com/signingbonus
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
>
>
-- 
Geir Magnusson Jr                                   203-247-1713(m)
geir@4quarters.com


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