I want to force the user to type a number with exact 2 digits after decimal point. Currently when the user types 12.349 it will be converted automatically to 12.35. Instead a validation error should be raised like: "please enter a number with 2 digits after decimal point."
class Accounting < ActiveRecord::Base
validates :share_ksk, :central_office, :limit_value, :fix_disagio,
presence: true, numericality: { less_than: 999.99, greater_than_or_equal_to: 0.00 }
end
my migration file:
class CreateAccountings < ActiveRecord::Migration
def change
create_table :accountings do |t|
t.decimal :share_ksk, precision: 5, scale: 2, null: false
t.decimal :central_office, precision: 5, scale: 2, null: false
t.decimal :limit_value, precision: 5, scale: 2, null: false
t.decimal :fix_disagio, precision: 5, scale: 2, null: false
t.timestamps null: false
end
end
end