You can actually do this without javascript, too. The built in expressions can do it, for the most part.
StrRepeat("0",(4 - StrLength(GlobalVariableString(GoldAsString)))) + GlobalVariableString(GoldAsString)
More info on how I did it back in 2020 here: Why isn't this code more efficient? - #6 by Silver-Streak