Possible Duplicate:
Format numbers in javascript
I have a string represents a number: "3507654" I need to split it on a parts, by 3, e.g "3 507 654"
Number can be any value, but always a number.
Possible Duplicate:
Format numbers in javascript
I have a string represents a number: "3507654" I need to split it on a parts, by 3, e.g "3 507 654"
Number can be any value, but always a number.
You could do the following:
"3507654".replace(/(\d)(?=(?:\d{3})+$)/g, "$1 ")
But this is not very efficient since it’s O(n2).