Forum Moderators: open
I am using a JavaScript (cobbled together from various other scripts, a bit messy but it works) to add/subtract/multipy some values entered into a form.
These are finacial figures, and so there is every chance that people will enter the values as, say, 30,000 rather than 30000. At them moment if they do the form cannot deal with it.
Is it possible to add figures entered in this format?
Or to have it so that it corrects to that format if they don't (or even vice versa)?
Also I am passing results from the form to another page where they are displayed - and would really like them to display with the commas.
Currently the script is using this to round figures:
function round(number,X) {
X = (!X? 2 : X);
return Math.round(number*Math.pow(10,X))/Math.pow(10,X);
}
var s = "";
for(var i=0; i<number.length; i++)
{
if((number.charAt(i) >= '0' && number.charAt(i) <= '9') ¦¦ number.charAt(i) == '.') s += number.charAt(i);
}
var newnum = parseFloat(s);