How can I improve comma insertion code?
Here is the code I have written. It works fine except if the input is a negative six-digit number, a comma appears just after the negative sign like so: -,963,562
This is part of a larger program, obviously, and one of the other things I need to do is have negative numbers like -45 recognized as valid but numbers like 4-5 not recognized as valid. I hope this is enough information for someone to help me.
if (validInput = true);
string comString = inString;
int length = comString.length();
int i = (comString.length() - 3);
while (i > 0)
comString.insert(i, 1, ',');
i = i - 3;