Sha256: d836d3bbb0cc4d97541d1a96da75639032500a8824defa0508da59f264b6c4ba
Contents?: true
Size: 624 Bytes
Versions: 1
Compression:
Stored size: 624 Bytes
Contents
# frozen_string_literal: true require 'bigdecimal' module Tikkie module Api # Helper for converting amounts to cents and back. class Amount class << self def from_cents(cents) amount = BigDecimal(cents) / 100 new(amount) end end def initialize(amount) @amount = BigDecimal(amount.to_s) end def to_d @amount end # Convert the amount to a String with 2 decimals. def to_s format("%.2f", @amount) end def to_cents cents = @amount * 100 cents.to_i end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
tikkie-api-2.0.0 | lib/tikkie/api/amount.rb |