How to strip commas from float input?

前端 未结 3 992
悲哀的现实
悲哀的现实 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:02

    I found the solution after looking at few places and combining few solutions, since I had to use gsub before the linking to model has to be done. so I created the method in my controller and called it before create and update action. and wrote the following code in the method

    params[:record][:Revenue] = params[:record][:Revenue].gsub(/,/,"")
    

提交回复
热议问题