> I think overall it's trying to parse a number where the
> thousands are separated by commas, into an integer.
To do this it would probably be enough to remove all the commas and then either, depending on the result you want, round() o sprintf("%d") the resulting string.
The (awful) code may be doing something more, however an example of the input would be nice to study. ;)