Sha256: 6dc2c688209066e894505dad9fa4c80f6aca35313da541bf61647c2c5fb4fe30

Contents?: true

Size: 1.93 KB

Versions: 1

Compression:

Stored size: 1.93 KB

Contents

= BigMoney

== Description

Represents an amount of money in a particular currency. Backed by BigDecimal, so it's safe from float rounding errors.

== Features

* Encapsulates an amount with its currency into a single object.
* Backed by BigDecimal, so it can store arbitrary-precision values without rounding errors. Useful if you're dealing
  with fractional cents.
* Optional currency exchange.
* Optional string parsing.

== Problems

* Does not implement all of Numeric, so doesn't quite act like a real number.

== Todo

* Has no Money package API compatibility to ease transition (module patch welcome).
  (http://dist.leetsoft.com/api/money/)

== Synopsis

=== Basic

  require 'big_money'
  BigMoney.default_currency = :aud

  bm = BigMoney.new('3.99')
  bm.amount           #=> BigDecimal.new('3.99')
  bm.currency         #=> BigMoney::Currency::AUD.instance
  bm.to_s             #=> '3.99'
  bm.to_s('$.2f')     #=> '$3.99'
  bm.to_s('$%.2f %s') #=> '$3.99 AUD'

  bm2 = 1.to_big_money
  bm + bm2 #=> BigMoney.new(4.99)
  bm + 1   #=> BigMoney.new(4.99)

=== Exchange

  require 'big_money'
  require 'big_money/exchange/yahoo' # Use yahoo finance exchange service.

  bm = BigMoney.new('3.99')
  bm.amount   #=> BigDecimal.new('3.99')
  bm.currency #=> BigMoney::Currency::USD.instance

  bm2 = bm.exchange(:aud)
  bm.amount   #=> BigDecimal.new('5.22')
  bm.currency #=> BigMoney::Currency::AUD.instance

=== Parser

  require 'big_money'
  require 'big_money/parser'

  BigMoney.parse('JPY ¥2500')   #=> BigMoney.new('2500', :jpy)
  BigMoney.parse('JPY2500')     #=> BigMoney.new('2500', :jpy)
  BigMoney.parse('2500JPY')     #=> BigMoney.new('2500', :jpy)
  BigMoney.parse('¥2500JPY')    #=> BigMoney.new('2500', :jpy)
  BigMoney.parse('¥2500', :jpy) #=> BigMoney.new('2500', :jpy)

== Install

* Via git:

    git clone git://github.com/mroch/big_money.git

* Via gem:

    gem inseall mroch-big_money -s http://gems.github.com

== License

See LICENSE.

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
shanna-big_money-0.3.0 README.rdoc