Использование Regex :
'56,883.90,607,219,945'.replace(/(\..{2}).*/,'$1')
Что соответствует всем вашим ожидаемым результатам:
56,883.90,607,219,945 => 56,883.90
5,327.078,363,188,421 => 5,327.07
1688.7000000000003 => 1688.70 (it will not add comma)
2,739.272 => 2,739.27
function changeToNumber(str) {
return str.replace(/(\..{2}).*/, '$1');
}
var input = ['56,883.90,607,219,945',
'5,327.078,363,188,421',
'1688.7000000000003',
'2,739.272'
]
input.forEach(function(value) {
console.log(changeToNumber(value));
});