-3

I change number to string

ex) 

721,011 => seven hundred twenty-one thousand eleven

21,011 => twenty-one thousand eleven

and i found split per three words

https://gist.github.com/hendriklammers/5231994

but it is splited at first word

 721,011 => [721, 011] (It is perfect)
 21,011 => [210, 11] (It is not perfect, wanna [21, 011])
 2123011 => [212, 301, 1] (It is not perfect, wanna [2, 123, 011])
 21230ef11 => [212, 301, 1] (It is not perfect, I'll accept only integer , wanna [2, 123, 011]), (using fucntion num.toString().replace(/\D/g, "") )

how to split string per length?

is it only reverse string and re reversing?

kai
  • 492
  • 3
  • 18
  • Please show your code. – Barmar Dec 11 '14 at 02:45
  • @Barmar now I'm started develop and find how to split words – kai Dec 11 '14 at 02:51
  • "split string per length" is not clear at all what you want. Please show sample input and desired output for several different inputs. – jfriend00 Dec 11 '14 at 02:51
  • @kai What does that mean? I asked you to show the code that isn't working the way you want it. You also need to explain better what you're trying to do. – Barmar Dec 11 '14 at 02:53
  • _not perfect_? Do you mean _wrong_? – Barmar Dec 11 '14 at 02:54
  • @Barmar I wanna split per three length words "123456789" is split per three words [123,456,789] and "1234567" is [1,234,567] – kai Dec 11 '14 at 02:58
  • Put that explanation in the question. And put your code that isn't working in the question. Then we'll probably reopen it. – Barmar Dec 11 '14 at 02:59
  • Not a perfect match, but there should be enough here to help: [*How to print a number with commas as thousands separators in JavaScript*](http://stackoverflow.com/questions/2901102/how-to-print-a-number-with-commas-as-thousands-separators-in-javascript) – RobG Dec 11 '14 at 03:06
  • Most English speakers would say "twenty one thousand and eleven". No, you don't have to reverse the string. – RobG Dec 11 '14 at 03:47

1 Answers1

1

If I don't understand your question entirely wrong, a simple

var a = '21,011'
var b = a.split(',');

should do the job.

baao
  • 71,625
  • 17
  • 143
  • 203
  • my text is "21,011" or "21011" or "2938dkdj"(change 2938) – kai Dec 11 '14 at 02:50
  • No, I think (?) he wants to split a number without commas into groups of three digits, for input into his algorithm to convert the number into words. –  Dec 11 '14 at 03:05