Convert string with comma to integer

mCY picture mCY · Jul 13, 2012 · Viewed 181.8k times · Source

Is there any neat method to convert "1,112" to integer 1112, instead of 1?

I've got one, but not neat:

"1,112".split(',').join.to_i #=> 1112

Answer

Michael Kohl picture Michael Kohl · Jul 13, 2012

How about this?

 "1,112".delete(',').to_i