Jump to content

Hide decimals with convertPrice function in smarty


Poppy381

Recommended Posts

Hi,

 

I was searching for a way to hide decimales while using convertPrice function which works with several currencies.

 

I've found a trick on the forum but it only works with one kind of currency.

 

Here is my trick and it works with all the different currencies format :

 

 

 

{if $currency->format == 1 || $currency->format == 4 || $currency->format == 5}

{convertPrice|regex_replace:'/[.][0-9]+/':'' price=$yourprice * $currency->conversion_rate}

{elseif $currency->format == 2 || $currency->format == 3}
{convertPrice|regex_replace:'/[,][0-9]+/':'' price=$yourprice * $currency->conversion_rate}
{else}
{convertPrice price=$yourprice* $currency->conversion_rate}
{/if}

 

If $yourprice is a productprice you don't have to write "*$currency->conversion rate". Just add $product.price :).

 

If you want to round your price : price=round($product.price)

 

The else can be empty, it's just in case of an override of the Tools.php with new specific format rules :).

 

Hope you like it :).

Edited by Poppy381 (see edit history)
  • Like 1
Link to comment
Share on other sites

  • 9 months later...

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...