Jump to content

Delete decimals on the prices


paby

Recommended Posts

Hello,

 

I sell products to high price in euros, which never have centimes.

 

I want that all the prices of my site, with the exception of the basket (because of the other amounts: the VAT, the postal charges…) are not shown with centimes.

 

E.g. 100 € and not 100,00 €

 

Have you any idea, somebody? <_<

 

Thanks !

 

Presta 1.4.7

Link to comment
Share on other sites

Hi,

 

You can change _PS_PRICE_DISPLAY_PRECISION_ in defines.inc.php

 

I had not try the behaviour for the cart, vat and transport.

 

You could also change the Tools function displayPrice to such behaviour :

- Product price 200.00 then display 200

- Product price 200.21 then display 200.21

 

The explanation is not clear but to sum it up : if there are decimals show them else do not (all of these in displayPrice function).

 

Bon developpement

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

Hi,

I have the solution you asked :

- let _PS_PRICE_DISPLAY_PRECISION_ unchanged (value = 2)

 

Make an override of the tools::displayPrice (copy and paste it in your override)

 

and modify this part of the code

switch ($c_format)
        {
             /* X 0,000.00 */
             case 1:
               $ret = $c_char.$blank.number_format($price, $c_decimals, '.', ',');
               break;
           /* 0 000,00 X*/
           case 2:
               $ret = number_format($price, $c_decimals, ',', ' ').$blank.$c_char;
               break;
           /* X 0.000,00 */
           case 3:
               $ret = $c_char.$blank.number_format($price, $c_decimals, ',', '.');
               break;
           /* 0,000.00 X */
           case 4:
               $ret = number_format($price, $c_decimals, '.', ',').$blank.$c_char;
               break;
       }

 

To this

$prix =(int)$price;   
		    if ($prix<$price){    // if $price not an integer then display decimals like configured
 switch ($c_format)
  {
 /* X 0,000.00 */
 case 1:
   $ret = $c_char.$blank.number_format($price, $c_decimals, '.', ',');
   break;
  /* 0 000,00 X*/
  case 2:
   $ret = number_format($price, $c_decimals, ',', ' ').$blank.$c_char;
   break;
  /* X 0.000,00 */
  case 3:
   $ret = $c_char.$blank.number_format($price, $c_decimals, ',', '.');
   break;
  /* 0,000.00 X */
  case 4:
   $ret = number_format($price, $c_decimals, '.', ',').$blank.$c_char;
   break;
 }
		    }
		    else {   // $price is a nice round price, do not display decimals
			    $ret = $price;
			    if ($c_format ==2 || $c_format==4){$ret.=$blank.$c_char;}

		    }

 

Then with this I have a product at 150.€ displayed and everything that need decimals will still be displayed with decimals.

  • Like 1
Link to comment
Share on other sites

  • 1 year later...
  • 2 months later...
  • 1 month later...
  • 1 year later...

Hi,

I have the solution you asked :

- let _PS_PRICE_DISPLAY_PRECISION_ unchanged (value = 2)

 

Make an override of the tools::displayPrice (copy and paste it in your override)

 

and modify this part of the code

switch ($c_format)
         {
              /* X 0,000.00 */
              case 1:
                $ret = $c_char.$blank.number_format($price, $c_decimals, '.', ',');
                break;
            /* 0 000,00 X*/
            case 2:
                $ret = number_format($price, $c_decimals, ',', ' ').$blank.$c_char;
                break;
            /* X 0.000,00 */
            case 3:
                $ret = $c_char.$blank.number_format($price, $c_decimals, ',', '.');
                break;
            /* 0,000.00 X */
            case 4:
                $ret = number_format($price, $c_decimals, '.', ',').$blank.$c_char;
                break;
        }
To this

$prix =(int)$price;   
			    if ($prix<$price){    // if $price not an integer then display decimals like configured
  switch ($c_format)
   {
	 /* X 0,000.00 */
	 case 1:
    $ret = $c_char.$blank.number_format($price, $c_decimals, '.', ',');
    break;
   /* 0 000,00 X*/
   case 2:
    $ret = number_format($price, $c_decimals, ',', ' ').$blank.$c_char;
    break;
   /* X 0.000,00 */
   case 3:
    $ret = $c_char.$blank.number_format($price, $c_decimals, ',', '.');
    break;
   /* 0,000.00 X */
   case 4:
    $ret = number_format($price, $c_decimals, '.', ',').$blank.$c_char;
    break;
  }
			    }
			    else {   // $price is a nice round price, do not display decimals
				    $ret = $price;
				    if ($c_format ==2 || $c_format==4){$ret.=$blank.$c_char;}
				   
			    }
Then with this I have a product at 150.€ displayed and everything that need decimals will still be displayed with decimals.

 

I need help!

The price of a product the price does not show decimal at all. It always rounds the price .

 

For example it shows this € 60 but not this € 60,50.

I have checked the round mode , you can choose 5 round mode but nothing changes this issue :(

 

 

Please help!

Link to comment
Share on other sites

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...