MV Is it possible to format a variable to separate with commas?

Hi all. As the title suggests, but of course I will elaborate more. What I mean is, by default, the engine stores variables like: 123456789. What I would like is for the variable storing a digit large enough to separate every 1,000. Example: 123,456,789.

I'm unsure if a script is needed or if a plugin needs to be made in order for this to be possible. I'm still learning script, so I would definitely appreciate the help! I tried searching for this in Google, but the only thing I found was a 3 year old post regarding this topic. So to avoid necro-posting, I just posted my own thread instead.
You wouldn't actually store it that way, unless you don't care about doing math with it and you convert it from a number to a string. In that case, you'd do
Control Variables -> Script -> "the number the way you want it to be displayed in quotes"

If you want it to be stored as a number, you can display it with the commas by doing the script call:
Code:
$gameVariables.value(69).toLocaleString();
That will display the value of variable 69 formatted with commas.

If you want to do that in the middle of, say, a Show Text command, you'd need to use something like Hakuen Studio's Escape Codes to be able to embed a JavaScript command.
Thank you for the quick reply! I will test this immediately and then reply back with results!
After testing, I did not get the result I was hoping for. I'm using ShowText command as well, btw using text code \v[varID]. How do I format the text code to separate with commas? Or does this require a plugin?

EDIT: Sorry I didn't see that plugin suggestion. Thank you! I will give that plugin a go!
If you always want the variables you reference that way to be formatted, you could try copying and pasting this into a text editor; save as a *.js file, include as a plugin:
Code:
Window_Base.prototype.convertEscapeCharacters = function(text) {
    text = text.replace(/\\/g, '\x1b');
    text = text.replace(/\x1b\x1b/g, '\\');
    text = text.replace(/\x1bV\[(\d+)\]/gi, function() {
        return $gameVariables.value(parseInt(arguments[1])).toLocaleString();
    }.bind(this));
    text = text.replace(/\x1bV\[(\d+)\]/gi, function() {
        return $gameVariables.value(parseInt(arguments[1])).toLocaleString();
    }.bind(this));
    text = text.replace(/\x1bN\[(\d+)\]/gi, function() {
        return this.actorName(parseInt(arguments[1]));
    }.bind(this));
    text = text.replace(/\x1bP\[(\d+)\]/gi, function() {
        return this.partyMemberName(parseInt(arguments[1]));
    }.bind(this));
    text = text.replace(/\x1bG/gi, TextManager.currencyUnit);
    return text;
};

and that should do it at a global level. But I'd probably go for Eli's plugin to have the control over when exactly it's being formatted.
AMAZING!! This beautiful plugin worked wonderfully! This thread can be closed please. Thank you so much!!
@CaptainGameMaker incase you want it slightly different and extend
ATT_Turans Solution for safety to keep V instact, you can use this one:

JavaScript:
Window_Base.prototype.convertEscapeCharacters = function(text) {
    text = text.replace(/\\/g, '\x1b');
    text = text.replace(/\x1b\x1b/g, '\\');
    text = text.replace(/\x1bV\[(\d+)\]/gi, function() {
        return $gameVariables.value(parseInt(arguments[1]))
    }.bind(this));
    text = text.replace(/\x1bV\[(\d+)\]/gi, function() {
        return $gameVariables.value(parseInt(arguments[1]))
    }.bind(this));
        text = text.replace(/\x1bVS\[(\d+)\]/gi, function() {
        return $gameVariables.value(parseInt(arguments[1])).toLocaleString();
    }.bind(this));
    text = text.replace(/\x1bVS\[(\d+)\]/gi, function() {
        return $gameVariables.value(parseInt(arguments[1])).toLocaleString();
    text = text.replace(/\x1bN\[(\d+)\]/gi, function() {
        return this.actorName(parseInt(arguments[1]));
    }.bind(this));
    text = text.replace(/\x1bP\[(\d+)\]/gi, function() {
        return this.partyMemberName(parseInt(arguments[1]));
    }.bind(this));
    text = text.replace(/\x1bG/gi, TextManager.currencyUnit);
    return text;
};

so \V[varId] show the value as normal, while \VS[varId] will use
VariableString and you can use both way as well.

this is of course optional though, depending if you always need it or temporally
if only some values need to be a string 🙂

Original thread: https://forums.rpgmakerweb.com/threads/is-it-possible-to-format-a-variable-to-separate-with-commas.162607/