I have a number is 1205000000, I want display at 1.205.000.000
number.toString().replace(/(\d{3})/g, "$1.").toString()
but result is 120.500.000.0 I don't want reverse a number.
I have a number is 1205000000, I want display at 1.205.000.000
number.toString().replace(/(\d{3})/g, "$1.").toString()
but result is 120.500.000.0 I don't want reverse a number.
One way would be to reverse the string before your manipulation and ther reverse it again. Like so:
var number = 1205000000;
function reverse(s) {
return s.split("").reverse().join("");
}
var str = reverse(reverse(number.toString()).replace(/(\d{3})/g, "$1."));
alert(str);
See this working fiddle.
EDIT: See the comments. Its a bit dirty but for that specific number it will work. The link posted by @Artyom Neustroev as a comment under you question seems a whole lot better than this here.
For the sake of correcting your regular expression (obviously for integer values only):
number.toString().replace(/(\d)(?=(?:\d{3})+$)/g, '$1.');