|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
tomseno Smarty n00b
Joined: 13 Dec 2015 Posts: 2
|
Posted: Sun Dec 13, 2015 7:43 pm Post subject: Replace in smarty |
|
|
Hallo!
Möchte gerne bei einem Preis der als String in einem Smarty gespeichert wird durch Zeichen ersetzen.
Code: | ecomm_totalvalue: {/literal}{$PRODUCTS_PRICE|regex_replace:'/[^0-9\.]/':''}{literal} |
{$PRODUCTS_PRICE} hier ist z.B. 1.300,00 EUR gespeichert - aussehen sollte es aber so: 1300.00
Dh. der Tausenderpunkt und "EUR" muss weg. und Das Komma muss als Dezimalpunkt dargestellt werden.
Kann mir bitte jemand helfe - hab obigen Ansatz von einem anderen Forum. Jedoch nach einer Woche rumprobieren bin ich noch nicht weiter.
Danke. lg |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Sun Dec 13, 2015 11:13 pm Post subject: |
|
|
If I understand your request right, you want to convert textual representation of the price into numerical.
Aside from questionable feasibility of such action (not all decimal fractions could be correctly represented in binary form), something like this could work:
Code: | {$PRODUCTS_PRICE|regex_replace:'/[^0-9\,]/':''|regex_replace:'/\,/':'.'} |
|
|
Back to top |
|
tomseno Smarty n00b
Joined: 13 Dec 2015 Posts: 2
|
Posted: Mon Dec 14, 2015 6:59 am Post subject: |
|
|
That's it!!!
thanks a lot |
|
Back to top |
|
elpmis Smarty Elite
Joined: 07 Jun 2007 Posts: 321
|
Posted: Mon Dec 14, 2015 7:19 am Post subject: |
|
|
Du solltest aber dabei bedenken, dass regex Operationen sehr performance-lastig sind.
Von daher hätte ich eher daran gedacht, den String in eine echte Zahl umzuwandeln, also z.Bsp.
Code: | {$PRODUCTS_PRICE|floatval} |
|
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|