Hello all! I am looking for a way to make my js interpret a comma (,) the same way it does a dot (.) in an input form. I am using the input forms for decimals that are being calculated, and here in Norway it's common to use the comma as a decimal separator. Thx Ken
Just replace comma with nothing. str = "32,200.100"; str = str.replace(",",""); numFloat = parseFloat(str); alert(numFloat); Code (markup): That should do it. Good luck
Maybe the best way to use eval() function? it seems to me that eval("0.0001") is the same with eval("0,0001")...
For this problem it is not security breach. Otherwise maybe u should to explain why it's so? What've to happen?
User can enter javascript code, with some pages it maybe harmful. Anyway, rule no.1 - don't use eval.
Anyway, i can enter ANY javascript code in browser. in address string enter javascript: document.body.contentEditable='true'; document,designeMode='on'; void 0; Code (markup): instead of address string. Work? Work! Enter javascript:alert('hahaha'); void 0; Code (markup): Work? So, u can use eval() function in the same way. javascript: alert(eval('0.001')); void 0; Code (markup):
You could try something like this: var v = document.getElementById("TextBox").value; if (v.indexOf(",") > -1) { v = v.replace(/,/, "."); } var n = parseFloat(v); Code (markup): But it won't handle numbers which have both a comma and a dot, such as: 1,000,000.00 or 1.000.000,00 You could make it check to see if it contains both characters, and if so, force the user to re-enter the number using one or the other.
Thank you all for replies! I think I'll go with vpguy's suggestion. I'm only working with one decimal for this one (XX,X) so I'll be fine. Again, thanks. Ken