seog Posted January 12, 2013 Share Posted January 12, 2013 Hi I would like know how display in prestashop 1.5 product price without decimals if the decimals are .00 I tried with the next options but it don´t work convertPrice price=$productPrice|string_format:"%.0f"|replace:".00":""} convertPrice price=$productPrice|remove:".00"} {convertPrice|string_format:"%d" price=$product.price} best regards Link to comment Share on other sites More sharing options...
PhiLho Posted January 14, 2013 Share Posted January 14, 2013 (edited) It is an interesting question, because you made me dig into Smarty and the source code... And lot of searches and some experimentations, I think the syntax you look for is: {convertPrice|replace:'.00':'' price=$productPrice} convertPrice returns a price converted to a string according to the current currency and decimal symbol. Beware if it returns a comma as decimal separator or more than two digits... A potentially robuster version can be: {convertPrice|regex_replace:'/[.,]0+$/':'' price=$productPrice} Edited January 14, 2013 by PhiLho (see edit history) 1 Link to comment Share on other sites More sharing options...
seog Posted January 15, 2013 Author Share Posted January 15, 2013 Thank for your contribution but this don´t work. I tried delete only decimals in product-list and product.tpl but only works in digits less than thousand with the next code {convertPrice|string_format:"%d" price=$product.price} If the price is 1000 or higher then the price displays only one digit example: if price is 1256 with this modification only displays " 1 " Do you know why? Link to comment Share on other sites More sharing options...
PhiLho Posted January 15, 2013 Share Posted January 15, 2013 (edited) I don't understand. Do you mean you tried my modifiers and they failed? Honestly, I just tried them on a small Smarty test code, not in PrestaShop yet. I will try on my test shop. convertPrice returns a string. I don't know a decimal string format works in PHP when given a string instead of a number. If it does an automatic conversion or if it errors. Edited January 15, 2013 by PhiLho (see edit history) Link to comment Share on other sites More sharing options...
PhiLho Posted January 15, 2013 Share Posted January 15, 2013 My |replace modifier failed on my shop, because it has comma as separator, not dot, as expected... I adjusted my regex modifier, because the currency symbol was part of the price: with |regex_replace:'/[.,]0+ /':' ' I was successful to replace 22,00 € with 22 €. Some adjustment might be needed in your case. Link to comment Share on other sites More sharing options...
seog Posted January 15, 2013 Author Share Posted January 15, 2013 (edited) Hi PhiLho, My shop have in backoffice a dot but in frontoffice displays comma. I tried replacing product-list with the your new code but the decimals don´t disappear {convertPrice|regex_replace:'/[.,]0+/':'' price=$product.price} Do you modified any frontcontroller file ? best regards Edited January 15, 2013 by seog (see edit history) Link to comment Share on other sites More sharing options...
seog Posted January 15, 2013 Author Share Posted January 15, 2013 ok, your code works perfect you're a genius Link to comment Share on other sites More sharing options...
vekia Posted January 15, 2013 Share Posted January 15, 2013 many thanks for sharing the solution. I marked this topic as solved Link to comment Share on other sites More sharing options...
death667b Posted June 5, 2014 Share Posted June 5, 2014 (edited) Thank-you! Just one of the options that should be in back-office I think. I just wanted to add that I removed the comma otherwise it was dropping any zero's after it. {convertPrice|regex_replace:'/[.]0+/':'' price=$product.price} Edit: For australian currency - if needed to know. Edited June 5, 2014 by death667b (see edit history) Link to comment Share on other sites More sharing options...
JAKCRABBIT Posted September 22, 2014 Share Posted September 22, 2014 (edited) Hi, I need to hide all decimals, not only if are .00, I mean: 1.500,41 -> 1.500, how to do it? But I need it only in FO, not BO too, so I cant to change currency settings with decimals to off. SOLVED: |regex_replace:'/[.,][0-9]+/':'' Edited September 22, 2014 by JAKCRABBIT (see edit history) Link to comment Share on other sites More sharing options...
babyewok Posted November 17, 2015 Share Posted November 17, 2015 It is an interesting question, because you made me dig into Smarty and the source code... And lot of searches and some experimentations, I think the syntax you look for is: {convertPrice|replace:'.00':'' price=$productPrice}convertPrice returns a price converted to a string according to the current currency and decimal symbol. Beware if it returns a comma as decimal separator or more than two digits...A potentially robuster version can be: {convertPrice|regex_replace:'/[.,]0+$/':'' price=$productPrice} This works great, but it fails when the product has combinations....any ideas? Link to comment Share on other sites More sharing options...
babyewok Posted November 24, 2015 Share Posted November 24, 2015 No one Link to comment Share on other sites More sharing options...
Mercader Virtual Posted March 21, 2019 Share Posted March 21, 2019 Prestashop 1.7 This solution is global. In my case I needed it that way. WARNING: If you setup prestashop with more than 2 decimals, this would mess up your numbers! This solution is only for 2 decimals configuration (default). /classes/Tools.php, line 719 Replace: return $cldr->getPrice($price, is_array($currency) ? $currency['iso_code'] : $currency->iso_code); With: $price = $cldr->getPrice($price, is_array($currency) ? $currency['iso_code'] : $currency->iso_code); return str_replace(".00", "", $price); Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now