How to strip commas from float input?

前端 未结 3 990
悲哀的现实
悲哀的现实 2021-01-25 04:12

I have a field -

:Revenue

and it should accept values like 10,000.00, but if I input such value it stores 10 into dat

3条回答
  •  孤城傲影
    2021-01-25 05:13

    Removing commas is pretty simple:

    value.gsub(/,/, '').to_f
    

    Keep in mind that European formatting often uses comma as the decimal value separator so your results would be off by a factor of 100 if processing those sorts of numbers.

提交回复
热议问题