Forum Discussion
KimGabites
4 years agoCommunity Member
Help with Java Script to format numbers
Hi everyone
Thank you for the awesome help on my last query around the characters. I have a new challenge I am hoping someone expert in java-script can help me with please. I am brand new to it, s...
KimGabites
4 years agoCommunity Member
Hi Math
The script brought up the dollar sign but it didnt put in any commas. What is the script for putting in commas as well please?
Cheers
Kim
var player=GetPlayer();
varTotAvailSav=playerGetVar("TotAvailSav");
varTotAvailSav=TotAvailSav.toFixed(0).replace(/\d(?=(\d{3})+\.)/g, '$&,');
vartxtvalue=TotAvailSav.toString();
player.SetVar("txtTotAvailSav",txtvalue);
SteveGannon
4 years agoCommunity Member
Kim,
If you do not want any decimal places, try replacing your third line of code with this line:
var TotAvailSav=TotAvailSav.toFixed().replace(/(\d)(?=(\d\d\d)+(?!\d))/g, '$&,');
If you do want two decimal places, keep your current third line but change...
toFixed(0)
...to...
toFixed(2)
- MathNotermans-94 years agoCommunity Member
Regex Master Steve to the rescue ;-)
Related Content
- 10 months ago
- 8 months ago
- 5 months ago
- 2 months ago