I know that as gamblers, everyone can relate to this question, as we have surely experienced it in real situations.
Suppose our bankroll is $100 and it has already grown to $500, would you quit or continue? Conversely, if with our bankroll, we are down to $10, would you still continue or save the remaining $10? I used specific amounts to make it easier to discuss this situation. I understand that we all gamble with different amounts based on our income, but consider this as an example. You can mention any amount you want based on your personal experience; it doesn't matter.
When to stop gambling depends on how you control your gambling. If one is involved in making money then it becomes really difficult to get rid of gambling. There are many who go to the point where they can't control their greed in order to get profit from gambling and thus they face losses instead of profits from gambling. There is another class of people who go to the point of losing money, where they keep betting repeatedly to recover the money they lost earlier, and eventually become bankrupt, but still cannot stop themselves from gambling.