JSFiddle - React, Tailwind, and code Playground
JavaScript
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);