javascript - Parsing a price with , and ,-- exception with parseFloat() -



javascript - Parsing a price with , and ,-- exception with parseFloat() -

i'm trying parse cost out of html document:

here how html element looks like:

<div> <span id="market_buynow_dialog_totals_total" class="market_dialog_totals_cost">0,11€</span> <span class="market_dialog_totals_label">total:</span> </div>

there , , don't want restricted either left or right side of ,, in illustration above love int 11 , 399,99 love 39999.

here current solution:

var currentprice = parsefloat(document.getelementbyid("market_buynow_dialog_totals_total").innerhtml.replace(/[,€]/g, ""));

however there exception breaks little solution: cost can 300,-- or 250,-- @ times. in cases currentpriceis 300 or 250 instead of desired 30000 or 25000.

i'm trying find elegant , short solution problem. can help me out?

try this:

var currentprice = parsefloat(document.getelementbyid("market_buynow_dialog_totals_total").innerhtml.replace(/[,€]/g, "").replace(/\d/g,'0'));

this convert remaining non-integers 0's.

javascript parsing parsefloat

Comments

Popular posts from this blog

c# - ASP.NET MVC Sequence contains no matching element -

java - Parsing XML, skip certain tags -

rest - How to invalidate user session on inactivity in a stateless server? -