Jump to content
Poppy381

Tips to round prices with NO decimals displayed with Prestashop 1.7.

Recommended Posts

Ok the problem is that the Prestashop team change a lot of things with currencies to use cldr.

The decimals feature does not work anymore even if the feature is on the BO.

Well after several hours of research I've find that :

 

 

If you want to know the conversion_rate, it's not visible on smarty debug windows but here :

 

$conversion_rate = $this->context->currency->conversion_rate;
$this->context->smarty->assign('conversion_rate',$conversion_rate);

Now, for the ROUND price. First configure Prestashop to really round your prices. Even if you round theme and select 0 decimals, 2 decimals will always been displayed. That's because prestashop 1.7 does not refer to your settings (thank you guys...) but to cldr.

 

If you want to know the format of your currency try this :

$currency_format = $this->context->currency->format;
echo $currency_format,
break;

The format is store in a local file in >Translations>cldr>main-en-US-numbers or main-fr-FR-numbers etc.

 

Open the file and find "currencyFormats-numberSystem-latn"

"currencyFormats-numberSystem-latn":{"currencySpacing":{"beforeCurrency":{"currencyMatch":"[:^S:]","surroundingMatch":"[:digit:]","insertBetween":"\u00a0"},"afterCurrency":{"currencyMatch":"[:^S:]","surroundingMatch":"[:digit:]","insertBetween":"\u00a0"[spam-filter],"accounting":"#,##0.00\u00a0\u00a4;(#,##0.00\u00a0\u00a4)","standard":"#,##0.00\u00a0\u00a4","unitPattern-count-one":"{0} {1}","unitPattern-count-other":"{0} {1}"}

you will find the currency format.

 

$ format :

standard:\u00a4#,##0.00

€ format :

standard: #,##0.00\u00a0\u00a4

\u00a4 is the currency sign

 

\u00a0 is a space

 

The coma is the thousand(group) separator and The point is the decimal separator.

They are defined at the beginning of the file :

"symbols-numberSystem-latn":{"decimal":".","group":",";

If you don't want to see decimals on your shop, just delete ".00" and save the file, and that's all :).

 

 

I suggest to Prestashop team to allow us to have a variable to display or not decimals instead of doing that :)

 

All the best

Franck

Edited by Poppy381 (see edit history)
  • Like 8
  • Thanks 2

Share this post


Link to post
Share on other sites

Well the first thing to do is to create your own thread on this forum and don't ask a question about something different in a thread...Please delete your message, you will have more answer in your own thread with a good title.

 

Thank you.

Share this post


Link to post
Share on other sites

Thanks for share!

 

But it's works? how do it, you can help i fix prestashop v1.7.2.1

 

Thanks!

 

hi Truong

as I suggested you, this topic is the original post which gives the solution

Edited by ets-soft (see edit history)

Share this post


Link to post
Share on other sites

Original post ? This topic answers to this problem on 29th November 2016 by myself, your topic on 29 June 2017 ?

I don't understand why you post another link to another forum as the answer is still here in the first post, with all explanations. Right ?

Share this post


Link to post
Share on other sites

Original post ? This topic answers to this problem on 29th November 2016 by myself, your topic on 29 June 2017 ?

I don't understand why you post another link to another forum as the answer is still here in the first post, with all explanations. Right ?

 

hi Poppy381

sorry for the mistake, I didn't know your post is original. @Trung Huynh asked us for help on another forum, I was looking for a solution on Google and saw it on stackoverflow and gave him that solution. I have edited the previous post

Share this post


Link to post
Share on other sites

Hi, I have tree currencies in my store, but I don't know how to configurate the correct currency format for every one.

 

EUR is X,XXX.XX €

USD is $X,XXX.XX

COP is $ X.XXX

 

I will waiting for a response (Sorry for my english)

Share this post


Link to post
Share on other sites

Hi,

Thanks, this worked well :)

Can i edit this file in order to make the prices end with a "9", for example 109?

Share this post


Link to post
Share on other sites

Sadly it doesn't work for me. I've edited the numbers.json according to your information in translations/cldr/datas/main/ko-KR. I don't use a CDN, caching is diabled and theme compiling is forced. None of the changes take effect. Even if I delete the content of the whole file.

Share this post


Link to post
Share on other sites
11 minutes ago, Vailry said:

Sadly it doesn't work for me. I've edited the numbers.json according to your information in translations/cldr/datas/main/ko-KR. I don't use a CDN, caching is diabled and theme compiling is forced. None of the changes take effect. Even if I delete the content of the whole file.

 

Clear cache and try again. If you delete the file and nothing change, it should help you to understand...Maybe something change on last version...

 

Share this post


Link to post
Share on other sites

Hello,
can you also advise me how to delete the decimal places in discount flags the list of products? E.g. 17.35% discount does not look nice. I would only show 17% (from 17.5% to 18%), etc.
"percentFormats-numberSystem-latn": {"standard": "#, ## 0 \ u00a0%"}, = 0 decimal places, but show all
Thank you in advance for your advice.

Share this post


Link to post
Share on other sites

Hello, I have the same issue, need to display Russian Ruble with no decimals, and Euro with 2 decimals.  

Is there a possible solution for multiple currencies?

Share this post


Link to post
Share on other sites

This solution is half working actually. If you remove .00 but your items has prices with decimals then final price will be incorrectly calculated in the basket.

As for an examle: you have product#1 with price "10.55", if you remove .00 at standard section of the file then its price will be shown at frontend as "10" but if you add 2 pcs of product#1 to the basket final price will be "21" but not "20". Additional removal of .00 at accounting section of the file does nothing.

Any ideas?

Share this post


Link to post
Share on other sites
On 11/29/2016 at 7:58 PM, Poppy381 said:

Ok the problem is that the Prestashop team change a lot of things with currencies to use cldr.

The decimals feature does not work anymore even if the feature is on the BO.

Well after several hours of research I've find that :

 

 

If you want to know the conversion_rate, it's not visible on smarty debug windows but here :

 


$conversion_rate = $this->context->currency->conversion_rate;
$this->context->smarty->assign('conversion_rate',$conversion_rate);

Now, for the ROUND price. First configure Prestashop to really round your prices. Even if you round theme and select 0 decimals, 2 decimals will always been displayed. That's because prestashop 1.7 does not refer to your settings (thank you guys...) but to cldr.

 

If you want to know the format of your currency try this :


$currency_format = $this->context->currency->format;
echo $currency_format,
break;

The format is store in a local file in >Translations>cldr>main-en-US-numbers or main-fr-FR-numbers etc.

 

Open the file and find "currencyFormats-numberSystem-latn"


"currencyFormats-numberSystem-latn":{"currencySpacing":{"beforeCurrency":{"currencyMatch":"[:^S:]","surroundingMatch":"[:digit:]","insertBetween":"\u00a0"},"afterCurrency":{"currencyMatch":"[:^S:]","surroundingMatch":"[:digit:]","insertBetween":"\u00a0"[spam-filter],"accounting":"#,##0.00\u00a0\u00a4;(#,##0.00\u00a0\u00a4)","standard":"#,##0.00\u00a0\u00a4","unitPattern-count-one":"{0} {1}","unitPattern-count-other":"{0} {1}"}

you will find the currency format.

 

$ format :


standard:\u00a4#,##0.00

€ format :


standard: #,##0.00\u00a0\u00a4

\u00a4 is the currency sign

 

\u00a0 is a space

 

The coma is the thousand(group) separator and The point is the decimal separator.

They are defined at the beginning of the file :


"symbols-numberSystem-latn":{"decimal":".","group":",";

If you don't want to see decimals on your shop, just delete ".00" and save the file, and that's all :).

 

 

I suggest to Prestashop team to allow us to have a variable to display or not decimals instead of doing that :)

 

All the best

Franck

i can not find file in here Translations>cldr>main-en-US-numbers
where is the file ?
please help me where i can find the file

Share this post


Link to post
Share on other sites

Hi, Translations>cldr> doesn´t work with 1.7.6?

I have two currencies and I would like to cancel the decimal places for CZK (1000 CZK), of course for EUR i need (1000.00 EUR).

Is any solution for 1.7.6? 

Share this post


Link to post
Share on other sites
On 7/24/2019 at 8:20 PM, Dusan K said:

Hi, Translations>cldr> doesn´t work with 1.7.6?

I have two currencies and I would like to cancel the decimal places for CZK (1000 CZK), of course for EUR i need (1000.00 EUR).

Is any solution for 1.7.6? 

Same here, update to 1.7.6 , decimal number showing again in product price
I checked the numbers file in cldr dir, is still same as before "standard":"\u00a4\u00a0#,##0"
In 1.7.5.x product price show $ 1
in 1.7.6 product price show $1 (without space) but in numbers file I add \u00a0

So can we assume numbers file in cldr not works in 1.7.6

But you can change in currency table, set precision field value to decimal number you want to show

 

Edited by pujionodk (see edit history)
  • Like 1

Share this post


Link to post
Share on other sites
On 8/12/2019 at 5:33 AM, pujionodk said:

Same here, update to 1.7.6 , decimal number showing again in product price
I checked the numbers file in cldr dir, is still same as before "standard":"\u00a4\u00a0#,##0"
In 1.7.5.x product price show $ 1
in 1.7.6 product price show $1 (without space) but in numbers file I add \u00a0

So can we assume numbers file in cldr not works in 1.7.6

But you can change in currency table, set precision field value to decimal number you want to show

 

I didnt know about precision in ps_currency table. Thanks a lot!

Share this post


Link to post
Share on other sites

Hello,

with 1.7.6.2 the precision in ps_currency is set to 3 but always seeing 2 decimals

Is it a template problem?

Searching since 2 days

Any help please?

Thank you in advance

Best regards

Share this post


Link to post
Share on other sites
Posted (edited)
On 11/29/2016 at 5:28 PM, Poppy381 said:

Ok the problem is that the Prestashop team change a lot of things with currencies to use cldr.

The decimals feature does not work anymore even if the feature is on the BO.

Well after several hours of research I've find that :

 

Nox Vidmate VLC

If you want to know the conversion_rate, it's not visible on smarty debug windows but here :

 


$conversion_rate = $this->context->currency->conversion_rate;
$this->context->smarty->assign('conversion_rate',$conversion_rate);

Now, for the ROUND price. First configure Prestashop to really round your prices. Even if you round theme and select 0 decimals, 2 decimals will always been displayed. That's because prestashop 1.7 does not refer to your settings (thank you guys...) but to cldr.

 

If you want to know the format of your currency try this :


$currency_format = $this->context->currency->format;
echo $currency_format,
break;

The format is store in a local file in >Translations>cldr>main-en-US-numbers or main-fr-FR-numbers etc.

 

Open the file and find "currencyFormats-numberSystem-latn"


"currencyFormats-numberSystem-latn":{"currencySpacing":{"beforeCurrency":{"currencyMatch":"[:^S:]","surroundingMatch":"[:digit:]","insertBetween":"\u00a0"},"afterCurrency":{"currencyMatch":"[:^S:]","surroundingMatch":"[:digit:]","insertBetween":"\u00a0"[spam-filter],"accounting":"#,##0.00\u00a0\u00a4;(#,##0.00\u00a0\u00a4)","standard":"#,##0.00\u00a0\u00a4","unitPattern-count-one":"{0} {1}","unitPattern-count-other":"{0} {1}"}

you will find the currency format.

 

$ format :


standard:\u00a4#,##0.00

€ format :


standard: #,##0.00\u00a0\u00a4

\u00a4 is the currency sign

 

\u00a0 is a space

 

The coma is the thousand(group) separator and The point is the decimal separator.

They are defined at the beginning of the file :


"symbols-numberSystem-latn":{"decimal":".","group":",";

If you don't want to see decimals on your shop, just delete ".00" and save the file, and that's all :).

 

 

I suggest to Prestashop team to allow us to have a variable to display or not decimals instead of doing that :)

 

All the best

Franck

IT works but, it was not detected by "list of modified files" lol

Edited by diondlemarcu (see edit history)

Share this post


Link to post
Share on other sites
On 1/7/2020 at 2:50 AM, diondlemarcu said:

IT works but, it was not detected by "list of modified files" lol

whith which version ?

Share this post


Link to post
Share on other sites

Bonjour, je n'ai pas de fichier dans le dossier translation/cldr/ 
juste un .htaccess

Savez vous pourquoi ?

version / 1.7.6.2

Share this post


Link to post
Share on other sites
On 1/13/2020 at 10:55 AM, fabmo31 said:

Bonjour, je n'ai pas de fichier dans le dossier translation/cldr/ 
juste un .htaccess

Savez vous pourquoi ?

version / 1.7.6.2

Bonjour as tu trouvé ? moi non plus j'ai rien trouvé

Edited by surfeur972 (see edit history)

Share this post


Link to post
Share on other sites

Hello,

Any news on this topic?

I searched my database for ps_currency using phpMyAdmin but that table doesn't seem to exist at all. Should it still be there in PS 1.7.6?

The seemingly simple problem of removing two tiny decimals from the price has proven to be more difficult than what I could ever imagine.

Any relevant input on this subject would be highly appreciated.

database-screenshot.png

Share this post


Link to post
Share on other sites
Posted (edited)

I'm sorry but i've found a way two years ago, and now Prestashop team changes everything without improving (you know the easy way : you put this option visible in the backoffice and it's over, it works and yes it was like that few years ago...).

It's a waste of time, just display the cents or move from Prestashop to .... mmm said https://sylius.com/ ? Good luck :).

Edited by Poppy381 (see edit history)

Share this post


Link to post
Share on other sites

Thanks for your reply! I can't believe they have made it so difficult. Perhaps I need to start a new thread?

I'm always open to try new platforms but I'm afraid Sylius does not appear to be comprehensive enough to cover all my needs, for example when it comes to common payment methods used in Sweden. Otherwise it looks nice and sleek.

Share this post


Link to post
Share on other sites

I was amazed when they launched PS1.7 how this kind of things becames difficult, and the new menu where everything is hidden in a tab.

I think Sylius integration with Symfony is what Prestashop would like to go :). I understand your special needs with payment integration so PS is maybe still good...but with cents displayed ^^.

 

 

Share this post


Link to post
Share on other sites

 a lot of devs have tried to solve this, I did it once with module 'price charming' but it would only work with 'tax excluded' I'm in the US so that made sense.  It's a lot more complicated than some pretty good devs (with passion) tried to solve and failed, I'm still hurting 5 years later.

the last module I saw on addon's to do this is no longer there.  here are a few but as mentioned the one that look close is no longer offered.  

https://addons.prestashop.com/en/search?search_query=rounding

 

Share this post


Link to post
Share on other sites

Thanks a lot for your input on this. I'm not sure if I should be amazed or terrified from your information... To be completely frank, the very need for a module in resolving this feels utterly absurd to me. Anyway, I'm testing my luck in this newly posted thread:

 

Share this post


Link to post
Share on other sites

Thanks a lot for your advice! I was aware of that module and in the end I will probably go for that solution. I just find it somewhat ridiculous to need a module for such basic functionality. For now I'll stick to Prestashop mainly due to the wide availability of third party payment modules, but I regret saying that I'll start considering other alternatives for the next major upgrade of my e-shop.

Share this post


Link to post
Share on other sites

PrestaShop had a 'very' good price display (by currency) in 1.6 and earlier versions.  They changed their localization pack process to use 'something else' and that beautiful feature was lost. 

I suppose they thought somebody would create a module to replace the feature.

I'll ask you this, if you use tax included, look at other ecommerce platforms and see if they support 'charming a price' with tax included...I don't think you will find any/many.  That is a really horrible law to require tax included....

 

 

 

 

Share this post


Link to post
Share on other sites

Hello,

I'm sorry to notice that for every little ordinary function we should pay 70 € or more

I'm afraid this is the end of Free prestashop !

Our concurrents are using other platforms and they are really doing a very good job with much less fees !!

What do you thinks guys ?

Share this post


Link to post
Share on other sites
On 3/25/2020 at 8:59 PM, roboy said:

Thanks a lot for your advice! I was aware of that module and in the end I will probably go for that solution. I just find it somewhat ridiculous to need a module for such basic functionality. For now I'll stick to Prestashop mainly due to the wide availability of third party payment modules, but I regret saying that I'll start considering other alternatives for the next major upgrade of my e-shop.

Hi Roboy, Do you have any feedback on that module? does it work as it should? 

 

On 3/26/2020 at 2:34 AM, Amorino said:

Hello,

I'm sorry to notice that for every little ordinary function we should pay 70 € or more

I'm afraid this is the end of Free prestashop !

Our concurrents are using other platforms and they are really doing a very good job with much less fees !!

What do you thinks guys ?

Im quite new to prestashop but the module prices that ive seen so far are crazy to be honest...

Share this post


Link to post
Share on other sites

Hello I've found a way for PS 1.7.5.0 It's maybe the same trick for PS1.7.6 whatever :

On the file  Prestashop_1_7_5_0/vendor/icanboogie/cldr/lib/NumberPattern.php

Ligne 275

public function format_integer_with_decimal($integer, $decimal, $decimal_symbol)
{       
    //FIRST TRICK : Remove decimals with a condition for example any price with decimal at 0
    if (in_array($decimal, array("0","00","000","0000","00000","000000"))) {            
        $decimal = null;
    } else {

      if ($this->decimal_digits > strlen($decimal)) {
          $decimal = str_pad($decimal, $this->decimal_digits, '0');
      }

      if (strlen($decimal)) {
          $decimal = $decimal_symbol . $decimal;
      }

    }

    //SECOND TRICK : Remove any decimals even if the price is 19,12 it will be displayed 19
    //remove the line below ($decimal = null;) if this is not what you wanted.
    $decimal = null;        

    return "$integer" . $decimal;
}

I've put 2 visions

- The first one is to remove decimals only if the real price is 19,00 € -> 19 € up to 6 decimals

- The second one is to remove decimals everywhere

 

I have not test that everywhere on the website but it seems ok

Hope its will be helpfull :). Tell me

Share this post


Link to post
Share on other sites

And now for the PS 1.7.6.4 let's remove this decimals...

File : prestashop1_7_6_4/src/Core/Localization/Number/Formatter.php

l.125

#REPLACE

if ($minorDigits) {
	$formattedNumber .= self::DECIMAL_SEPARATOR_PLACEHOLDER . $minorDigits;
}

#BY

if (in_array($minorDigits, array("0","00","000","0000","00000","000000"))) {            
	//$formattedNumber = $formattedNumber;
} else if ($minorDigits) {
	$formattedNumber .= self::DECIMAL_SEPARATOR_PLACEHOLDER . $minorDigits;
}

Still the same tricks, i only remove decimals from prices that have "0" in decimals

Save then refresh your page...End of story.

 

 

You can easely observe my past comment with my 2 last answers : Any new version change the way they are dealing with displayPrice... Good luck with future versions guys ahahahaha ! Disable one click automatic update :D !

  • Like 1

Share this post


Link to post
Share on other sites

Wow!! That worked wonders. Great to feel that one can still count on the Prestashop community! You ought to be upgraded to guru status 😃. One last question: Should I modify the original Formatter.php and keep notes for future updates to Prestashop, or could I simply use the override feature in order to avoid having to redo the change on each version update?

Share this post


Link to post
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...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More