Topic: Storing Money as Cents (integers)
I've been reading around on how to store money in the database and decided on storing them as integers (thus changing the amount to cents).
This is what I came up with to check before creating a record if it is a float:
class Transaction < ActiveRecord::Base
before_create :check_if cents
if self.amount.class.to_s == "Float"
cents_amount = 100 * self.amount
self.amount = cents_amount.to_i
is this what I'm looking for? Or am I going about this the wrong way.