@mikefromruauthorMar 09.2018 — #I read your request in post #1 as to put the '.' after the FIRST character, not the last.
To me that would be 1.000 instead of 1000.
If 'coothead's answer was good enough for you, then OK.[/QUOTE] No, his answer isn't right for me. I don't understen why he answered so. You're right. Actually I already did it.
@JMRKERMar 10.2018 — #Could also use: <i> </i>var a = 1000, b = a.toLocaleString("en").replace('.',','); alert(b);
or <i> </i>var a = (1000).toLocaleString("en").replace('.',','); alert(a); var b = (9999).toLocaleString("en").replace('.',','); alert(b); var c = (19999).toLocaleString("en").replace('.',','); alert(c); var d = (500).toLocaleString("en").replace('.',','); alert(d);
@rootMar 10.2018 — #This was asked in another thread the other day and I posted a nice prototype REGEX option for formatting a string with a comma, you just need to swap the , for a . and f you good to go for numbers like 1, 1.00, 100.000 and so on.
Number.prototype.numberFormat = function(){ return this.toString().replace( /(d)(?=(d{3})+(?!d))/g, "$1," ); }; Use: [B]var myResult = myNumber.numberFormat();[/B] to get the number formatted as a number with commas.
This should work Number.prototype.numberDotFormat = function(){ return this.toString().replace( /(d)(?=(d{3})+(?!d))/g, "$1." ); }; Use: [B]var myResult = myNumber.numberDotFormat();[/B] to get the format you want.
@wbportMar 10.2018 — #I think he would want to keep the original number intact (so it could be manipulated further) and keep another "number" (really character string) to display. Some locales use "." for a decimal point and "," to separate groups of three digits in front of it, for some it is vice versa. Perhaps put the code to do this in a function so what the function returns could be displayed or printed.
[B]Never mind, I see this was implemented in the previous post.[/B]