Am trying to remove trailing zeros after , or . in a currency, still retaining the currency sign. For example, €90.00 to €90, 90.00€ to 90€ and €90.33 to €90.33.
The example can be found below:
$('.product-price-wrapp').each(function() {
var productPrice = $(this).find('.price').text();
var trimPrice = productPrice.substr(0,productPrice.indexOf(','));
productPrice.text(trimPrice);
});
body {
padding: 20px;
background: #20262E;
font-family: Helvetica;
}
.price {
color: green;
}
.price span {
color: #747474;
}
.price:first-child,
.price:last-child,
.price:nth-of-type(6){
color: red;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.1/jquery.min.js"></script>
<div class="product-price-wrapp">
<div class="price"><span>Product Price</span> 90,00 €</div>
<br>
<div class="price"><span>Product Price</span> 90,30 €</div>
<br>
<div class="price"><span>Product Price</span> 90,45 €</div>
<br>
<div class="price"><span>Product Price</span> 92,67 €</div>
<br>
<div class="price"><span>Product Price</span> 33.33 €</div>
<br>
<div class="price"><span>Product Price</span> £22.00</div>
<br>
<div class="price"><span>Product Price</span> £72,22</div>
<br>
<div class="price"><span>Product Price</span> £72,00</div>
</div>
WORKING VERSION: JSFiddle
You are all amazing, thanks a lot to you all for your help! Credit: @Cocest @A. Ramos @Ivan