str_for_num is unlikely to contain a random bug because that's a very simple function. It's probably something else.

Can you do the test script that I suggested, and if the problem then still happens, send it to Support? We'll then look into this.