Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
Advanced Search
  • 1

How to remove trailing decimal .00's from product pricing


MarikaS

Question

16 answers to this question

Recommended Posts

  • 1

The code was written in 2016 and like many of the older code samples provided on forums, it therefore understandably doesn’t take into account the introduction of Ajax on many Squarespace templates since that time. Turning off Ajax in Site Styles will fix this but it’s just a workaround. A better solution is to replace

(function() {

with

window.Squarespace.onInitialize(Y, function() {

If like me you’d like to understand why, I wrote an explanation here: https://sf.digital/squarespace-solutions/why-doesnt-my-code-work-until-i-refresh-the-page

Edited by paul2009

About Paul: Circle Community Leader who values honesty, transparency, respect and appreciation ♥.
Work: Squarespace Expert and founder of 
SF Digital, a company dedicated to improving Squarespace websites by building the features Squarespace didn't include™. See our range of extensions for Squarespace to improve your store.
Content: Links in my posts may refer to SF Digital products or may be affiliate links.

Link to comment
  • 0

About Paul: Circle Community Leader who values honesty, transparency, respect and appreciation ♥.
Work: Squarespace Expert and founder of 
SF Digital, a company dedicated to improving Squarespace websites by building the features Squarespace didn't include™. See our range of extensions for Squarespace to improve your store.
Content: Links in my posts may refer to SF Digital products or may be affiliate links.

Link to comment
  • 0

Been there too @Brandon!

The Community team have now imported the old Answers post 👍

 

About Paul: Circle Community Leader who values honesty, transparency, respect and appreciation ♥.
Work: Squarespace Expert and founder of 
SF Digital, a company dedicated to improving Squarespace websites by building the features Squarespace didn't include™. See our range of extensions for Squarespace to improve your store.
Content: Links in my posts may refer to SF Digital products or may be affiliate links.

Link to comment
  • 0

Thanks @brandon and @paul2009 for this code! It works perfectly when I first save it in the foot code injection, but as soon as I refresh a page, it reverts to the normal pricing with decimals again. I wonder if it's because our prices are in £ rather than $. I've tried swapping the currencies out in the code but I really don't know what I'm doing! Any ideas how I could get it to work?

Here's an example of what I'm working with: https://ellishampers.co.uk/hampers/magnificent-n8-the-marvel

 

UPDATE:

Just checked that the above linked worked and the decimals had disappeared! Tried in incognito and they came back again. It seems that if I refresh the page the code works, but the first time I load it the decimals are always there. In normal browsing (not incognito), the same applies but every time you load the page, you also see the decimals briefly before they disappear. Worth putting the code in the header for this or is that something that could go wrong?

Thank you! 😊

Edited by EllisCo
Link to comment
  • 0

Hi, thank you very much for this solution, I've found this to work great for me as well apart from a single instance when I choose two variables of a product to add to cart - such as a size and a color. When two variables are chosen, suddenly the two decimals appear again. Any idea why that might be and if there's a way to solve this?

Link to comment
  • 0

 

About Paul: Circle Community Leader who values honesty, transparency, respect and appreciation ♥.
Work: Squarespace Expert and founder of 
SF Digital, a company dedicated to improving Squarespace websites by building the features Squarespace didn't include™. See our range of extensions for Squarespace to improve your store.
Content: Links in my posts may refer to SF Digital products or may be affiliate links.

Link to comment
  • 0

Hi - I am wondering if it is possible to switch between variants?

I want anything with trailing double decimals to display without them - for example $250.00 should display as $250. But I still want to keep my trailing decimals on my little numbers - for example I want $1.50 to display as that - not $1.5

Is that possible or an impossibility?

 

I have used the footer injection here - can it be edited to support this?

<script>

window.Squarespace.onInitialize(Y, function() {

       var prices = document.getElementsByClassName('sqs-money-native');

   var thisPrice;

   var i, I;

   for (i=0, I=prices.length; i<I; i++) {

       thisPrice = prices[i];

       thisPrice.innerHTML = thisPrice.innerHTML.replace(/(\.[0-9]*?)0+$/, "$1").replace(/\.$/, ""); //http://stackoverflow.com/questions/1015402/1015434#1015434

   }

   })();

Link to comment
  • 0

@misimo

Please post the URL for a page on your site where we can see your issue.

If your site is not public please set up a site-wide password, if you've not already done so.

Post the password here.

Adding a site-wide password is not a security breach. Please read the documentation at the link provided to understand how it works.

Please read the documentation at the link provided on how to share a link to your site to understand how it works. A link to the backend of the your site won’t work for us, i.e. a url that contains /config/.

We can then take a look at your issue.

Find my contributions useful? Please like, upvote, mark my answer as best , and see my profile. Thanks for your support!

Link to comment
  • 0

I'm also trying to remove decimals, I've tried a code that was linked here (see below) which has worked mostly, however it turns 11.90 into 11.9 and so on. I don't want to delete all the zeros. Can anyone help?

<script>
   (function() {
       var prices = document.getElementsByClassName('sqs-money-native');
   var thisPrice;
   var i, I;
   for (i=0, I=prices.length; i<I; i++) {
       thisPrice = prices[i];
       thisPrice.innerHTML = thisPrice.innerHTML.replace(/(\.[0-9]*?)0+$/, "$1").replace(/\.$/, ""); //http://stackoverflow.com/questions/1015402/1015434#1015434
   }
   })();
</script>

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

×
×
  • Create New...