René Beneš
René Beneš

Reputation: 468

Insert space before three zeros

I am working on jquery slider to take min and max price and I need help to insert space before each 3 zeros.
for example: I need 5000 to become 5 000
50000 = 50 000
Can you help me? Thanks alot

Upvotes: 0

Views: 398

Answers (1)

ruakh
ruakh

Reputation: 183602

You could write:

var splitIndex = (s.length + 2) % 3 + 1;
s = s.substr(0, splitIndex) + s.substr(splitIndex).replace(/\d\d\d/g, ' $&');

Upvotes: 2

Related Questions