I have a view that output decimal values that represent money data types on the database. To output I am using the following formatting code
string price = String.Format("{0:f}", (item.Price + item.VAT));
that produce a string like this
12,99 (with comma as the decimal separator)
I am now using this string to make some calculation on the client using jQuery
elmProductSelected.children("option").each(function(n) {
var pIdx = $(this).attr("rel");
var pObj = products.eq(pIdx);
var pValue = $(this).attr("value");
var valueArray = pValue.split('|');
var prdId = valueArray[0];
var pQty = valueArray[1];
/* the value of pPrice is 12,99 after the following call */
var pPrice = $(pObj).attr(attrProductPrice);
/* I get NaN here! */
sTotal = sTotal + ((pPrice - 0) * (pQty - 0));
cProductCount++;
cItemCount = cItemCount + (pQty-0);
});
I am getting NaN right on the line I have commented. I suppose that this is due to the fact that the pPrice
value use the comma as the decimal separator because if I manually set it as 12.99
everything works.
Is there a way to read the 12,99
as a number using javascript/jQuery?