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

Can someone help me change coding to get rid of decimal places in my pricing?


bahamascollective

Question

Recommended Posts

  • 0

Site URL: https://rocksforlife.com

Could anyone help me out removing two last zeroes from product price?
 
Example: 15,000.00 to 15,000 (so still keeping the comma in between)
 
The code I used (and which is not achieving my desired result):
 
<script>!function(){function reformatPrice(price){var priceClone=price.cloneNode(!0);function reformat(){priceClone.innerHTML=price.innerHTML;var target=priceClone.querySelector(".sqs-money-native")||priceClone,textNode=priceClone.querySelector(".sqs-money-native");target.textContent.length>1?target.textContent=format(target.textContent):textNode&&(textNode.textContent=format(textNode.textContent))}function format(text){return text.replace(",","").replace(/\.\d{2}/,"")}function watch(){var observer;new MutationObserver(reformat).observe(price,{childList:!0})}priceClone.classList.add("product-price-clone"),price.parentNode.insertBefore(priceClone,price.nextElementSibling),price.style.display="none",reformat(),watch()}ready(".product-price:not(.product-price-clone),.original-price:not(.product-price-clone)",reformatPrice)}();</script>
Link to comment
  • 0
Posted (edited)
17 hours ago, ievavi said:

What if reformatting needs to be from 15,000.00 to 15,000 (so still keeping the comma in between) ?

Simply delete this from the code:

.replace(",","") 

(see highlighted section below)

1961179985_Screenshot2021-06-04at10_09_55.png.bb38c41bafddaa11b73e37c4c9883bc6.png

 

Edited by paul2009

sf-digital-signature-logo-email145.png.46606a2288a2847f44d81b9b7b58f3a5.png
Hi! I'm Paul, an independent Squarespace Consultant since 2007 and founder of SF Digital, building the features that Squarespace didn't include. Our mini-extensions allow you to pick dates in any format, show prices in other currencies, take orders without payment or improve your cartI value honesty, integrity, transparency and respect . Links in my posts may refer to SF Digital products or may be affiliate links.

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