Jump to content

3 Decimal Currencies


Recommended Posts

It is just formating, when I go to catalog -> products ans in prices tab I try set price for ex. 1,123 the presta cut it to 1,12.

Also in cart I always have 0,00 - should be 0,00.

 

I found similar problem here http://www.prestashop.com/forums/topic/169748-3-decimal-currencies/ but solution is for older presta ..

Because in 1.5 it's look:

 

/* X 0,000.00 */

case 1:

$ret = $c_char.$blank.number_format($price, $c_decimals, '.', ',');

break;

 

How change $c_decimals to get 3 places after coma?

Link to comment
Share on other sites

I have 5 options in formatting but it don't change it but I see that it work and change currency symbol from left side to right side.

But it is for price 1.123.123 - I need smaller value like 1,123 - this is not the same..

 

Look on my shop http://dm-components.com - the resistor price should be smaller than 0.01 pounds.

It should be 0.005 for example. So I need 3 places.

Link to comment
Share on other sites

  • 3 months later...

This is pretty sad the way its been implemented, but here is how you support 3 decimal places in Prestashop v1.5. Keep in mind, this is a global site change, so it will impact currencies that are only 2 decimal places. All Prices will be shown with 3 decimals if you make this change.

 

To summarize, you would need to make the following changes to use a 3 decimal place price. Read below for more details

1) Change the config/defines.inc.php

 

define('_PS_PRICE_DISPLAY_PRECISION_', 3);

2) Override Tools::ps_round so the precision is switched globally from 2 to 3

3) Search for the usage of string_format, and ensure 3f is used instead of 2f. I only get 2 hits when I search, which is prices.tpl and AdminRangePriceController.php

 

The detailed explanation

1. Change the config/defines.inc.php

There is a config file named defines.inc.php, which has a setting _PS_PRICE_DISPLAY_PRECISION_

define('_PS_PRICE_DISPLAY_PRECISION_', 2);

This is used by the Tools::displayPrice function in conjunction with the currency format to show the price on a majority of the site. I changed the 2 to a 3 on a local test site and it seems to be working 90%.

 

2. Override Tools::ps_round

There are still some places where only 2 decimals are showing, and that is because of functions like Product::getPriceStatic and Product::priceCalculation also do decimal formatting, and instead of using the above setting, they hard coded 2. So in the AdminProductsController, where the product price is entered, rounds the price to 2 decimal

Product::getPriceStatic($this->_list[$i]['id_product'], true, null, 2, null, false, true, 1, true);

 

Those functions just pass the decimal value to Tools::ps_round, so a simple override of the ps_round function, you could do

if ($precision==2) $precision=3

 

3. Search for the usage of string_format

The last thing I could find is within the actual smarty templates, there is also price formatting. For example, in prices.tpl (which is used to show the admin product price), they are using string_format:'%.2f'

This is taking the 3 decimal price, and formatting it to 2 decimal, so changing it to string_format:'%.3f' fixes that display issue.

I suppose you could just remove the string_format entirely, but that will result in showing the full 6 decimal places

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

  • 4 weeks later...

There seems to be modifications to be done in the databases also. For instance, the structure of table 'ps_product' field 'additional_shipping_cost' = decimal(20,2) should be changed to decimal(20,3).

 

Edit: You also have to change '.toFixed(2)' to '.toFixed(3)' in price.js

Edited by T0x1c (see edit history)
Link to comment
Share on other sites

  • 3 weeks later...

Hi guys,

I am using version 1.5.3.1. I replaced all values of ps_round(xx,2) with ps_round(xx,3), and string_format = '%2f' with string_format = '%3f' (and of course the value precision on the defines.inc.php file).

 

You can find on attach all the edited files. Just unzip the file, and upload the content of the "prestashop 3 decimals" folder on the root of your prestashop installation. This will overwrite the 35 files which need to be edited.

If you want to rollback to a previous files, just unzip the content of the "prestashop 2 decimals" folder on the root, and all edited files will be restored.

 

I just tried it, and it seems to work for me.

prestashop 1.5.3.1 with 3 decimals.zip

Link to comment
Share on other sites

  • 5 weeks later...

another way to handle 3 decimal places it to simply turn decimals off for that currency and select, while it may not cover every instance it covers most..for example Colombia Peso's. We turn off decimals and consider the last three digits as decimal places.

 

04.13.2013-09.01.13.png

http://screencast.com/t/CLEdHIrFzUJZ

 

The problem we saw doing this, as well as with two digit decimal places were odd endings...so I wrote our Price Charming module so we could have some control of how 2/3 decimal endings looked.

Link to comment
Share on other sites

  • 8 months later...

Hi guys,

I am using version 1.5.3.1. I replaced all values of ps_round(xx,2) with ps_round(xx,3), and string_format = '%2f' with string_format = '%3f' (and of course the value precision on the defines.inc.php file).

 

You can find on attach all the edited files. Just unzip the file, and upload the content of the "prestashop 3 decimals" folder on the root of your prestashop installation. This will overwrite the 35 files which need to be edited.

If you want to rollback to a previous files, just unzip the content of the "prestashop 2 decimals" folder on the root, and all edited files will be restored.

 

I just tried it, and it seems to work for me.

 

And here is the files updated for 1.5.6.1 version: prestashop 1.5.6.1 with 3 decimals.zip

  • Like 1
Link to comment
Share on other sites

  • 8 months later...
  • 1 year later...
  • 1 year later...
×
×
  • Create New...