class Docdata::Order::Amount
Helper for converting/formatting amounts.
Public Class Methods
from_cents(cents)
click to toggle source
# File lib/docdata/order/amount.rb, line 10 def from_cents(cents) new(cents.to_i / 100.0) end
new(amount)
click to toggle source
# File lib/docdata/order/amount.rb, line 15 def initialize(amount) @amount = BigDecimal(amount.to_s) end
Public Instance Methods
to_amount()
click to toggle source
# File lib/docdata/order/amount.rb, line 23 def to_amount @amount / 100.0 end
to_cents()
click to toggle source
# File lib/docdata/order/amount.rb, line 27 def to_cents cents = @amount * 100 cents.to_i end
to_d()
click to toggle source
# File lib/docdata/order/amount.rb, line 19 def to_d @amount end
to_s()
click to toggle source
Convert the amount to a String with 2 decimals.
# File lib/docdata/order/amount.rb, line 33 def to_s format("%.2f", @amount) end