I have a rails model using postgres, with a height_value column, which is set as a decimal.
I want to store values without the trailing zeros, but I am thinking this is not possible with a decimal column type?
If it's not possible to store them this way, what is the best approach to trim off the trailing zeros in my model to make them always display properly. Should I change the column, is there a precision that would do what I want?
so if height_value:
28.5 => 28.5
28.0 => 28
19.75 => 19.75
19.00 => 19
Schema
create_table "buildings", force: true do |t|
t.decimal "height_value"
end
numerictype (which I think Rails callsdecimal) should behave exactly how you want if it is defined in the database as simplenumeric, with no precision or scale set. You may have a challenge getting Rails to it, though.