I am showing prices in span class want to add all the prices.To do that I have to remove the currency(which is dynamic).
data will be
<div class="js-price-cell"> <span class="js-price">$280.00</span> </div> <div class="js-price-cell"> <span class="js-price">$280.00</span> </div>
I tried with
$form.find('.js-price-cell').each(function () { let priceText= $(this).find('.js-price').text(); var itemTotal= parseFloat(priceText.replace(/[^0-9]/gi, '')); totalAmt += itemTotal; });
Instead of 560.00. It is giving as 56000. Seems like even the . is getting replaced.
.
You replaced the priceText: all non-decimals are removed. Add a . to the regex and it should work.
var itemTotal= parseFloat(priceText.replace(/[^0-9.]/gi, ''));
2.1m questions
2.1m answers
60 comments
57.0k users