-1

Hello there i have problem in jQuery. Suppose i have a value like 20000. And i want the value like 20,000 that after two number a comma will be inserted. I can't do it using jQuery. Please anyone help me out.

Fabrício Matté
  • 69,329
  • 26
  • 129
  • 166
Subir
  • 130
  • 1
  • 3
  • 10

1 Answers1

0

Since you said you want the comman inserted "after two numbers", I'm going to assume you have the easy case where you know that your input is a 5 digit number and don't want a more generic number formatting solution. In that case you can do something just like:

var num = 20000;

num = num.toString();
num = num.substr(0,2) + ',' + num.substr(2);
// Now num === "20,000"

Note that 20,000 will only read as twenty-thousand in certain locales. It could be read as just twenty in many locales, but 20000 will be read correctly by anyone who understands Arabic numerals.

Paul
  • 139,544
  • 27
  • 275
  • 264