I think this does what you want. I grabbed a script from Stack Overflow (no sense in rebuilding the wheel) and ran the user created variable myNum through it. I then reassigned the formatted result back to the myNum variable.
To make it right align I just changed the paragraph setting on the text box to align-right.
The .awt file is in the zip as well. Hope this helps.