
decimal=".";
var bits = num.split(decimal, 2),
I am getting an error at the above line when I pass num field as a parameter to this method// However it was running fine before..
function parseFloatOpts(num, decimal, thousands) {
var bits = num.split(decimal, 2),
ones = bits[0].replace(new RegExp('\\' + thousands, 'g'), '');
ones = parseFloat(ones, 10),
decimal = parseFloat('0.' + bits[1], 10);
return ones + decimal;
}
Examples:
parseFloatOpts("100.000,22", ',', '.'); //100000.22
parseFloatOpts("100,000.22", '.', ','); //100000.22
this is working fine..
But if I call the same method by passing parameters at run time.. then it gives the below error:
Object doesn't support property or method 'split'
2 个回答
Paddy,
I am not sure how where the method is called and what values you are passing in runtime.. chances are that the num variable is not being a string and you are trying to call the Split method on a non string..
to be safe, you can convert num to string and then apply the split method.. something like this..
var bits = num.toString().split(decimal, 2)...