When dealing with large numbers over 1,000, is there a way to String them so that they automatically display commas? Or do I have to it manually?
What about spaces?
Rather than 1,000, how do we do 1 000?
The method toLocaleString() converts a number to a string with the current locale setting. You can add a locale like toLocaleString(‘en’) for commas and toLocaleString(‘en’) for the French format with spaces and commas instead of periods. Otherwise, I believe it’s automatic.
// Get Value from Scene Variable Names varNum let Value = runtimeScene.getVariables().get("varNum").getAsNumber(); //convert to local style and set to string variable varFormated Number using commas as in English let FormattedNum = Value.toLocaleString('en'); runtimeScene.getVariables().get("varFormatedNum").setString(FormattedNum); //convert to French style and set to string variable varFrenchFormated Number using spaces as in French let FrenchFormat = Value.toLocaleString('fr-FR'); runtimeScene.getVariables().get("varFrenchFormatedNum").setString(FrenchFormat);
NOTE: this probably needs some checks and balances to make sure you’re providing a number and not text.