Alternatively, you can transform the data to an array of strings and make an if condition, that when a string (in this case our number) consits of more or is equal to 4 characters, you set the second field to comma add print out the rest, although much more practical is to use the actual function tony provided. This is just a other-way-around solution you could use in programming languages that do not provide such function.
Here's a graphical illustration of how it would work for easier comprehension
if a number <= 4 characters
print out the number
else
make every character of the number into an array
for example the standard input would be 1258
set the 0th string to 1st character which would be 1 second to comma etc
in this case
--------------------
[0][1][2][3][4]
1 . 2 5 8
--------------------
Doesn't really matter how large the number would be, you can create a for loop that keeps on extending the array until we use all the characters from input.
Important is only adding the first number and the comma.
It's a pretty stupid/binary solution, but I didn't think of anything better that could be universally applied to pretty much any programming language. Obviously there are easier ways to do it, without even having to do this, but this is like easiest way to do it that would work with pretty much everything.
Though yeah, use the function if you can, no need to complicate our lives.