Discussion:
[Freemarker-devel] Currency w/ out currency symbol
Andy Zeneski
2003-06-06 16:40:05 UTC
Permalink
Looking for a way to format a currency for an input box. So the currency
symbol should not be shown.

So, what I want is ${price?string.currency?substring(1)}

Any suggestions?

-Andy
Chris Nokleberg
2003-06-06 16:55:13 UTC
Permalink
Post by Andy Zeneski
Looking for a way to format a currency for an input box. So the currency
symbol should not be shown.
So, what I want is ${price?string.currency?substring(1)}
Any suggestions?
In the latest CVS, you could make this a function:

<#function mycurrency value>
<#return value?string.currency?substring(1)>
</#function>

${mycurrency(price)}

Of course you could just write a method in Java to do the same thing,
and put it into your model.

If you don't care about locale, you can just hard-code the format:
${price?string("0.00")}

Chris
Andy Zeneski
2003-06-06 17:00:05 UTC
Permalink
Is there a ?substring built-in? Didn't show up as valid in eclipse.

-Andy

----- Original Message -----
From: "Chris Nokleberg" <***@sixlegs.com>
To: <freemarker-***@lists.sourceforge.net>
Sent: Friday, June 06, 2003 2:55 PM
Subject: Re: [Freemarker-devel] Currency w/ out currency symbol
Post by Chris Nokleberg
Post by Andy Zeneski
Looking for a way to format a currency for an input box. So the currency
symbol should not be shown.
So, what I want is ${price?string.currency?substring(1)}
Any suggestions?
<#function mycurrency value>
<#return value?string.currency?substring(1)>
</#function>
${mycurrency(price)}
Of course you could just write a method in Java to do the same thing,
and put it into your model.
${price?string("0.00")}
Chris
-------------------------------------------------------
This SF.net email is sponsored by: Etnus, makers of TotalView, The best
thread debugger on the planet. Designed with thread debugging features
you've never dreamed of, try TotalView 6 free at www.etnus.com.
_______________________________________________
FreeMarker-devel mailing list
https://lists.sourceforge.net/lists/listinfo/freemarker-devel
Daniel Dekany
2003-06-06 17:08:19 UTC
Permalink
Post by Andy Zeneski
Is there a ?substring built-in? Didn't show up as valid in eclipse.
No, but you can use operator: str[first..last]
--
Best regards,
Daniel Dekany
Andy Zeneski
2003-06-06 17:17:06 UTC
Permalink
What if I don't know what last is? I need str[1..]

Actually what I am doing is price?string.currency[1..?]
price?string.currency[1..price?length] does not work due to the fact that
the trailing 0 is not there if price = 3.4

-Andy

----- Original Message -----
From: "Daniel Dekany" <***@freemail.hu>
To: "Andy Zeneski" <freemarker-***@lists.sourceforge.net>
Sent: Friday, June 06, 2003 3:07 PM
Subject: Re: [Freemarker-devel] Currency w/ out currency symbol
Post by Daniel Dekany
Post by Andy Zeneski
Is there a ?substring built-in? Didn't show up as valid in eclipse.
No, but you can use operator: str[first..last]
--
Best regards,
Daniel Dekany
-------------------------------------------------------
This SF.net email is sponsored by: Etnus, makers of TotalView, The best
thread debugger on the planet. Designed with thread debugging features
you've never dreamed of, try TotalView 6 free at www.etnus.com.
_______________________________________________
FreeMarker-devel mailing list
https://lists.sourceforge.net/lists/listinfo/freemarker-devel
Chris Nokleberg
2003-06-06 17:32:05 UTC
Permalink
Post by Andy Zeneski
What if I don't know what last is? I need str[1..]
Actually what I am doing is price?string.currency[1..?]
price?string.currency[1..price?length] does not work due to the fact that
the trailing 0 is not there if price = 3.4
Sorry, you'll need to do something like

<#function mycurrency value>
<#local value = value?string.currency>
<#return value[1 .. value?length - 1]>
</#function>

${mycurrency(4.2)}

prints "4.20" in my locale. (I tested this time...)

-Chris
Andy Zeneski
2003-06-06 17:36:04 UTC
Permalink
Yea, well that's a pain in the butt, needs to be a one liner. should add a
[1..*]

-Andy

----- Original Message -----
From: "Chris Nokleberg" <***@sixlegs.com>
To: <freemarker-***@lists.sourceforge.net>
Sent: Friday, June 06, 2003 3:32 PM
Subject: Re: [Freemarker-devel] Currency w/ out currency symbol
Post by Chris Nokleberg
Post by Andy Zeneski
What if I don't know what last is? I need str[1..]
Actually what I am doing is price?string.currency[1..?]
price?string.currency[1..price?length] does not work due to the fact that
the trailing 0 is not there if price = 3.4
Sorry, you'll need to do something like
<#function mycurrency value>
<#local value = value?string.currency>
<#return value[1 .. value?length - 1]>
</#function>
${mycurrency(4.2)}
prints "4.20" in my locale. (I tested this time...)
-Chris
-------------------------------------------------------
This SF.net email is sponsored by: Etnus, makers of TotalView, The best
thread debugger on the planet. Designed with thread debugging features
you've never dreamed of, try TotalView 6 free at www.etnus.com.
_______________________________________________
FreeMarker-devel mailing list
https://lists.sourceforge.net/lists/listinfo/freemarker-devel
Chris Nokleberg
2003-06-06 17:49:03 UTC
Permalink
Post by Andy Zeneski
Yea, well that's a pain in the butt, needs to be a one liner. should add a
[1..*]
I'm not against that, though it might give the parser fits.

FWIW this will also work ;-)

${price?string.currency?replace("$","")}

Chris
Andy Zeneski
2003-06-06 17:55:10 UTC
Permalink
But only if I know the symbol.. can I do a replace index?

-Andy

----- Original Message -----
From: "Chris Nokleberg" <***@sixlegs.com>
To: <freemarker-***@lists.sourceforge.net>
Sent: Friday, June 06, 2003 3:48 PM
Subject: Re: [Freemarker-devel] Currency w/ out currency symbol
Post by Chris Nokleberg
Post by Andy Zeneski
Yea, well that's a pain in the butt, needs to be a one liner. should add a
[1..*]
I'm not against that, though it might give the parser fits.
FWIW this will also work ;-)
${price?string.currency?replace("$","")}
Chris
-------------------------------------------------------
This SF.net email is sponsored by: Etnus, makers of TotalView, The best
thread debugger on the planet. Designed with thread debugging features
you've never dreamed of, try TotalView 6 free at www.etnus.com.
_______________________________________________
FreeMarker-devel mailing list
https://lists.sourceforge.net/lists/listinfo/freemarker-devel
Daniel Dekany
2003-06-06 21:12:07 UTC
Permalink
Post by Andy Zeneski
But only if I know the symbol..
Well, if you want to be really country independent, then substring(1)
would not work either. For example, we write currency amounts as this:
123 Ft
Post by Andy Zeneski
can I do a replace index?
No...

BTW, [1..*]. I think that the introduction of [x..y] as sub-string
operator was a mistake. So I'm not too enthusiastic to continue on this
line. Maybe it would be better to introduce ?substring(x[, y]) then...
I'm not sure.
--
Best regards,
Daniel Dekany
Andy Zeneski
2003-06-06 21:22:07 UTC
Permalink
You are correct and I think that formatting ##0.00 should do the trick. It
appears that the decimal is locale aware so it should be all good.

-Andy

----- Original Message -----
From: "Daniel Dekany" <***@freemail.hu>
To: "Andy Zeneski" <freemarker-***@lists.sourceforge.net>
Sent: Friday, June 06, 2003 7:10 PM
Subject: Re: [Freemarker-devel] Currency w/ out currency symbol
Post by Daniel Dekany
Post by Andy Zeneski
But only if I know the symbol..
Well, if you want to be really country independent, then substring(1)
123 Ft
Post by Andy Zeneski
can I do a replace index?
No...
BTW, [1..*]. I think that the introduction of [x..y] as sub-string
operator was a mistake. So I'm not too enthusiastic to continue on this
line. Maybe it would be better to introduce ?substring(x[, y]) then...
I'm not sure.
--
Best regards,
Daniel Dekany
-------------------------------------------------------
This SF.net email is sponsored by: Etnus, makers of TotalView, The best
thread debugger on the planet. Designed with thread debugging features
you've never dreamed of, try TotalView 6 free at www.etnus.com.
_______________________________________________
FreeMarker-devel mailing list
https://lists.sourceforge.net/lists/listinfo/freemarker-devel
Andy Zeneski
2003-06-06 18:06:03 UTC
Permalink
I guess ${price?string("##0.00")} should do the trick...

-Andy

----- Original Message -----
From: "Chris Nokleberg" <***@sixlegs.com>
To: <freemarker-***@lists.sourceforge.net>
Sent: Friday, June 06, 2003 3:48 PM
Subject: Re: [Freemarker-devel] Currency w/ out currency symbol
Post by Chris Nokleberg
Post by Andy Zeneski
Yea, well that's a pain in the butt, needs to be a one liner. should add a
[1..*]
I'm not against that, though it might give the parser fits.
FWIW this will also work ;-)
${price?string.currency?replace("$","")}
Chris
-------------------------------------------------------
This SF.net email is sponsored by: Etnus, makers of TotalView, The best
thread debugger on the planet. Designed with thread debugging features
you've never dreamed of, try TotalView 6 free at www.etnus.com.
_______________________________________________
FreeMarker-devel mailing list
https://lists.sourceforge.net/lists/listinfo/freemarker-devel
Attila Szegedi
2003-06-07 06:23:03 UTC
Permalink
Wow. I like this syntax. I'm +1 on supporting it.
Attila.

----- Original Message -----
From: "Andy Zeneski" <***@ofbiz.org>
To: <freemarker-***@lists.sourceforge.net>
Sent: Friday, June 06, 2003 9:35 PM
Subject: Re: [Freemarker-devel] Currency w/ out currency symbol
Post by Andy Zeneski
Yea, well that's a pain in the butt, needs to be a one liner. should add a
[1..*]
-Andy
----- Original Message -----
Sent: Friday, June 06, 2003 3:32 PM
Subject: Re: [Freemarker-devel] Currency w/ out currency symbol
Post by Chris Nokleberg
Post by Andy Zeneski
What if I don't know what last is? I need str[1..]
Actually what I am doing is price?string.currency[1..?]
price?string.currency[1..price?length] does not work due to the fact
that
Post by Chris Nokleberg
Post by Andy Zeneski
the trailing 0 is not there if price = 3.4
Sorry, you'll need to do something like
<#function mycurrency value>
<#local value = value?string.currency>
<#return value[1 .. value?length - 1]>
</#function>
${mycurrency(4.2)}
prints "4.20" in my locale. (I tested this time...)
-Chris
-------------------------------------------------------
This SF.net email is sponsored by: Etnus, makers of TotalView, The best
thread debugger on the planet. Designed with thread debugging features
you've never dreamed of, try TotalView 6 free at www.etnus.com.
_______________________________________________
FreeMarker-devel mailing list
https://lists.sourceforge.net/lists/listinfo/freemarker-devel
-------------------------------------------------------
This SF.net email is sponsored by: Etnus, makers of TotalView, The best
thread debugger on the planet. Designed with thread debugging features
you've never dreamed of, try TotalView 6 free at www.etnus.com.
_______________________________________________
FreeMarker-devel mailing list
https://lists.sourceforge.net/lists/listinfo/freemarker-devel
Daniel Dekany
2003-06-07 07:18:06 UTC
Permalink
Post by Attila Szegedi
Wow. I like this syntax. I'm +1 on supporting it.
Attila.
I don't understand why does it use "*". Shouldn't it be rather [1..]?

And BTW, if it works for strings, then it has to work with sequences as
well.
--
Best regards,
Daniel Dekany
Andy Zeneski
2003-06-07 12:28:03 UTC
Permalink
I only suggested a '*' so you would know what I meant. Any character would
do, or even no character like what Daniel suggested. It would be very useful
for sequences too.

-Andy

----- Original Message -----
From: "Daniel Dekany" <***@freemail.hu>
To: "Attila Szegedi" <freemarker-***@lists.sourceforge.net>
Sent: Saturday, June 07, 2003 5:15 AM
Subject: Re: [Freemarker-devel] Currency w/ out currency symbol
Post by Daniel Dekany
Post by Attila Szegedi
Wow. I like this syntax. I'm +1 on supporting it.
Attila.
I don't understand why does it use "*". Shouldn't it be rather [1..]?
And BTW, if it works for strings, then it has to work with sequences as
well.
--
Best regards,
Daniel Dekany
-------------------------------------------------------
This SF.net email is sponsored by: Etnus, makers of TotalView, The best
thread debugger on the planet. Designed with thread debugging features
you've never dreamed of, try TotalView 6 free at www.etnus.com.
_______________________________________________
FreeMarker-devel mailing list
https://lists.sourceforge.net/lists/listinfo/freemarker-devel
Jonathan Revusky
2003-06-07 12:37:02 UTC
Permalink
Post by Andy Zeneski
I only suggested a '*' so you would know what I meant. Any character would
do, or even no character like what Daniel suggested. It would be very useful
for sequences too.
Well, if it works for strings, we'll have it work for sequences for sure.

I think it might be better just from a pure parser POV to use an
elipsis, i.e. 3 dots.

myString[3...]

Not very hard to do, and probably desirable, though we're rather busy
with some other things right now.

Jonathan
Post by Andy Zeneski
-Andy
----- Original Message -----
Sent: Saturday, June 07, 2003 5:15 AM
Subject: Re: [Freemarker-devel] Currency w/ out currency symbol
Post by Daniel Dekany
Post by Attila Szegedi
Wow. I like this syntax. I'm +1 on supporting it.
Attila.
I don't understand why does it use "*". Shouldn't it be rather [1..]?
And BTW, if it works for strings, then it has to work with sequences as
well.
--
Best regards,
Daniel Dekany
-------------------------------------------------------
This SF.net email is sponsored by: Etnus, makers of TotalView, The best
thread debugger on the planet. Designed with thread debugging features
you've never dreamed of, try TotalView 6 free at www.etnus.com.
_______________________________________________
FreeMarker-devel mailing list
https://lists.sourceforge.net/lists/listinfo/freemarker-devel
-------------------------------------------------------
This SF.net email is sponsored by: Etnus, makers of TotalView, The best
thread debugger on the planet. Designed with thread debugging features
you've never dreamed of, try TotalView 6 free at www.etnus.com.
_______________________________________________
FreeMarker-devel mailing list
https://lists.sourceforge.net/lists/listinfo/freemarker-devel
Loading...