且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

将逗号转换为定界符

更新时间:2023-02-20 08:46:08

您所做的可能不是***的方法,因此也许有人可以用更好的方法回答。但是,要使您的生产线正常工作,您需要使其实际上保持更改。

What you're doing may not be the best way, so perhaps someone can answer with a better approach. But to get your line working you need to make it actually persist the change.

self.price.to_s.gsub(',', '.').to_f

只会返回更改,但不会随处可见

Will just return the change, but that doesn't go anywhere in a callback!

self.price = self.price.to_s.gsub(',', '.').to_f
# OR
self.price.to_s.gsub!(',', '.').to_f

将更改保留在对象中。