In my Ruby on Rails app, I've got a model called Post which has a column named "Price" in it's database table; this column is decimal type with a precision of 8 and scale of 2.
The form for a new Post has a 'text_field' for :price, and in the Post show view, I've setup "Price" to display this way ->
<p>
<strong>Price:</strong>
<%= number_to_currency(@post.price) %>
</p>
-My problem: the Price only displays correctly if the user inputs the value WITHOUT any commas. If the user puts in their desired numerical value with commas included, the Price ends up rendering as if they meant to put a decimal; hence making the displayed value too low
(example: If a user puts 67,000 as the value for the Price field, it will be saved/displayed as 67.00).
How could this be fixed so that even if the user includes commas in their originally typed value for Price, it will be displayed correctly...? And inversely, if the user doesn't include commas, a method so that the resulting output to the Show view is correctly styled with the commas for thousands/millions places...?