Jump to content

[SOLVED] How to display 3 decimals without rounding?


Recommended Posts

I have been trying to modify the tools.js and price.js (JS Folder) to get a 3 decimals price (without the default 2 decimals rounding) but I can't make it work.

Can anyone have a look? I need to display 1,027€ instead of 1,03€. Maybe is only changing one function.

Thanks in advance! ;)

Link to comment
Share on other sites

I finally got it working. The main problem was the ps_orders table (fields were "decimal(17,2) NOT NULL DEFAULT '0.00'" and I needed "decimal(17,3) NOT NULL DEFAULT '0.000'").

Anyway I changed classes/tools.php, classes/product.php and classes/cart.php to fix the display and external rounding issues.

I attach the changes maded (maybe it's not optimized because is prepared to work in all cases).

modifDecimals.docx

Link to comment
Share on other sites

  • 6 months later...
  • 2 weeks later...

Hello

Jupiterr

 

 

can you explain me how did you do???

i try but i dont know what i will change in classes/tools.php, classes/product.php and classes/cart.php

 

and modifDecimals.docx i dont fiend it

 

Thanks in advance! ;)

 

I'm sorry about that. I will write it down on my calendar to have a look post about that. I hope it will be today. Anyway, I will reupload that file (rewrited).

 

Good luck.

Link to comment
Share on other sites

  • 2 months later...

Thank you very much for the help Jupiterr. You saved my life :P

 

[Off Topic] Please next time try to write directly the code instead of upload a file, just in case the file wont be accesible (like this time). [/Off Topic]

 

So, summary and replying to hoss:

 

Make Prestashop using 3 decimals and don't rounding into 2:

 

1º) Change global variable _PS_PRICE_DISPLAY_PRECISION_ to 3 (or the number of decimals you need...) in file /config/defines.inc.php

 

This is supossed to be the one and only thing to change, BUT some static coding in other files that doesn't use this variable make our life harder... (at least till version 1.4.5, dont know if in next versions this is solved, if not... PLEASE PRESTASHOP TAKE NOTE OF THIS BUG!!!)

 

Well... next steps... :P

 

2º) Search for function Tools::ps_round( *price*, *decimals*) in this files:

classes/Cart.php

classes/Tools.php

classes/Product.php

controllers/ProductController.php

 

And algo keep an eye to this files, they have hardcoded the function with 2 decimals, so they most problably will need to be changed... (not tested yet)

 

admin/tabs/AdminOrders.php

admin/tabs/AdminProducts.php

classes/Order.php

classes/PDF.php

classes/PaymentModule.php

 

And change all the static *decimals* parameter from 2 to 3.

 

Hope this will clarify the issue to someone for won't an afternoon looking for the solution like me hehe.

 

Best Regards!

  • Like 1
Link to comment
Share on other sites

I'm coming back to report another issue...

 

Function Product::getPriceStatic is also hardcoded and also is used for format/round prices, so you have to search for this function and change the 4º parameter when necessary from 2 to 3.

 

Sorry if i don't detail all the files the function is in (searching for it is easy with "search in files" function of any decent text editor (like Komodo for MAC or Notepad++ for Windows), but after a long afternoon searching hardcoded variables... i need to go to gym :P

 

Best Regards!

Link to comment
Share on other sites

  • 10 months later...
  • 3 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...