Question

I work on a project base on prestashop cms.

This cms use smarty and i need to modify a tpl file to display a price without decimal.

I just want to modify one tpl and not applying this trick to full website

I found in another thread a code to remove null decimals like this 51,00

convertPrice|regex_replace:'/[.,]0+/':'' 

But i don't know how to change this code to remove decimal decimals like this too: 51,85 transform to 51

Many thanks R

Was it helpful?

Solution 2

change the 0+ into [0-9]+ or \d+. Both means any digits.

convertPrice|regex_replace:'/[.,][0-9]+/':''

OTHER TIPS

If you want to round the number (ie. anything above 0.5 becomes 1), you can use the following to display the price:

{number_format($price, 0)}

Documentation here: php.net/number_format

User number_format function without parameters. Like this

  {$price|number_format}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top