Hi everyone,
I have an odd situation where i am looping through an array, nice basic stuff. I can show the loop works through alerts.
What i want to do in the loop is some string manipulation to sum the values and generate a total.
My array is values like 2,000.00 and 14.65 ... cash values.
If in my array i pass out the value to a function i have called "unformat" the return value is what i want but the loop ends...
So, if there there is 2 lines i.e. this.lines.length = 2 then it will loop through for the first item and then not continue, if there is more than 2 lines then it will still go through once and stop. This means that my total is always the same as the the value of line 1.
here is the code...
The unformat function is like this
It seems really odd to me as i cannot see why the loop is being ended, could the parseFloat cause a problem with the 'i' indice in the loop?
Could the unformat function be a problem as it is not part of the JS object where the data is?
any suggestions would be great thanks.
Jez
I have an odd situation where i am looping through an array, nice basic stuff. I can show the loop works through alerts.
What i want to do in the loop is some string manipulation to sum the values and generate a total.
My array is values like 2,000.00 and 14.65 ... cash values.
If in my array i pass out the value to a function i have called "unformat" the return value is what i want but the loop ends...
So, if there there is 2 lines i.e. this.lines.length = 2 then it will loop through for the first item and then not continue, if there is more than 2 lines then it will still go through once and stop. This means that my total is always the same as the the value of line 1.
here is the code...
Code:
var lineTotals = 0;
alert("num lines " + this.lines.length);
for(i=0;i<this.lines.length;i++){
var tmp = parseFloat(unformat(this.lines[i][5]));
lineTotals += (parseFloat(lineTotals) + parseFloat(tmp));
}
The unformat function is like this
Code:
function unformat(sText){
var unformatted = "";
for (i = 0; i < sText.length; i++)
{
//alert(sText.charAt(i));
if(sText.charAt(i) != ",")
{
unformatted += sText.charAt(i);
}
}
return (unformatted);
}
It seems really odd to me as i cannot see why the loop is being ended, could the parseFloat cause a problem with the 'i' indice in the loop?
Could the unformat function be a problem as it is not part of the JS object where the data is?
any suggestions would be great thanks.
Jez