I have a jquery code in which I am reading a sub-total value from a div tag and then I want to convert it into a javascript number type. So I used the below code.
var cart_subtotal_str = $('.pewc-total-field').text(); // so it strips all HTML tags here
var cart_subtotal = cart_subtotal_str.replace('£', ''); // removes currency sign
var cart_subtotal_num = parseFloat(cart_subtotal); // here it returns NaN
The content of the div is like this
<span id="pewc-grand-total" class="pewc-total-field"><span class="woocommerce-Price-amount amount"><bdi><span class="woocommerce-Price-currencySymbol">£</span>8.40</bdi></span></span>
Any idea why and how do I fix this? I found that if I manually pass some string like this, it works fine.
var cart_subtotal_str = '12.34';
I have already read this answer, this question is not relevant to that Parsefloat always returns NaN
