Payment is a project mainly written in Ruby, based on the MIT license.
Small Rails plugin for working with money-like values
Small Rails plugin for convenient work with money-like column types.
For a columns named like 'pay_' or 'pay', adds corresponding methods 'payment' or '_payment', which work with object of Payment::Money class. This class behaves much as native Float, but also handles rounding issues. Also, when doing assignment, plugin performs banker's rounding by default
rails plugin install [email protected]:akuzko/payment.git
class Pay < ActiveRecord::Base
end
Pay.create :pay_amount => 12.3456, :total_pay => 34.5678 pay = Pay.last pay.pay_amount.class # => BigDecimal pay.pay_amount.to_f # => 12.35 - rounding performed by DB pay.payment_amount.class # => Payment::Money pay.payment_amount = 12.345 pay.pay_amount.to_f # => 12.34 - rounding performed by money proxy (half-even banker's rounding)
pay.total_payment # => 34.57 pay.total_payment do |float|
float * 33.567 end pay.total_payment # => 1160.41119 pay.total_pay.to_f # => 1160.41
Copyright (c) 2011 Artem Kuzko, released under the MIT license