I previously had this question: Rails Amounts in Thousands Are Truncated
However, I've run into the issue again with numbers that are greater than 1000, but don't have a comma.
So, for example, when "1590" is read in from a JSON response, my DB stores 1.00
in the DB for reg_price
.
[
{
"reg_price": "1590"
}
]
Schema
create_table "products", force: :cascade do |t|
t.decimal "reg_price", precision: 10, scale: 2
end
Model
response = open_url(url_string).to_s
products = JSON.parse(response)
products.each do |product|
product = Product.new(
reg_price: item['reg_price'].gsub(',', ''),
)
product.save
end
Thank you!