Here is the scenario
I am getting a value from user which I have to parse to float by rounding it up to a certain decimal point but user value can contain ","
I need to put , at same place where it was in user value for example if user entered +55,658,698.2396
and value is to be parsed to 2 decimal points the output should be +55,658,698.24
but after parsing I get +55658698.24
Here is the sample code
var userInput = "+54,568,568.14589";
var decimalPoints = 3;
var convertedValue;
var indexP = userInput.indexOf("+");
//getting rid of commas
var value = userInput.replace(/,/g , "");
value =parseFloat(value).toFixed(decimalPoints);
convertedValue = value.toString();
if(indexP == 0){
console.log('Converted Value: +'+convertedValue);
}
else{
console.log('Converted Value: '+convertedValue);
}
console.log('Actual Value: '+userInput);
and Here is the Fiddle http://jsfiddle.net/k5jhha4r/