skip to Main Content
Menu

Taking out comma from a numeric string

Ever encountered some nutty code wherein a div had a numeric value but with a “,”? As a newbie on jquery, this drenched the life out of me..  anyway to make the long story short, below is what i did:

// the comma between the forward slashes indicate that this is the character we are looking for.
var re = /,/gi;

// first we store the value of the div or span with id unit_price
var str = $("#unit_price").html() ;

// then we replace the comma with nothing.
var xprice = str.replace(re, "");
$("#total_order").html((parseFloat(qty) * parseFloat(xprice)).formatMoney(2,".",","));

Alphonse

Editorial Staff at ETN Multimedia is led by Alphonse Tan. Page maintained by Alphonse Tan

Back To Top