All Projects → theocodes → monetized

theocodes / monetized

Licence: MIT license
A lightweight solution for handling and storing money.

Programming Languages

elixir
2628 projects

Projects that are alternatives of or similar to monetized

currency-conversion
Convert Money Amounts between currencies.
Stars: ✭ 19 (-58.7%)
Mutual labels:  money, currencies
Countries
Countries - ISO 3166 (ISO3166-1, ISO3166, Digit, Alpha-2 and Alpha-3) countries codes and names (on eng and rus), ISO 4217 currency designators, ITU-T E.164 IDD calling phone codes, countries capitals, UN M.49 regions codes, ccTLD countries domains, IOC/NOC and FIFA letters codes, VERY FAST, NO maps[], NO slices[], NO init() funcs, NO external links/files/data, NO interface{}, NO specific dependencies, Databases/JSON/GOB/XML/CSV compatible, Emoji countries flags and currencies support, full support ISO-3166-1, ISO-4217, ITU-T E.164, Unicode CLDR and ccTLD standarts.
Stars: ✭ 85 (+84.78%)
Mutual labels:  money, currencies
currency-converter
💰 Easily convert between 32 currencies
Stars: ✭ 16 (-65.22%)
Mutual labels:  money, currencies
django-prices-openexchangerates
openexchangerates.org support for django-prices
Stars: ✭ 33 (-28.26%)
Mutual labels:  money, currencies
Cash Cli
💰💰 Convert currency rates directly from your terminal!
Stars: ✭ 168 (+265.22%)
Mutual labels:  money, currencies
EasyMoney-Widgets
The widgets (EditText and TextView) for support of money requirements like currency, number formatting, comma formatting etc.
Stars: ✭ 91 (+97.83%)
Mutual labels:  money, currencies
Oxr
💱 Node.js wrapper for the Open Exchange Rates API
Stars: ✭ 72 (+56.52%)
Mutual labels:  money, currencies
SimpleTypes
The universal PHP library to convert any values and measures (money, weight, currency converter, length, etc.).
Stars: ✭ 56 (+21.74%)
Mutual labels:  money, currencies
Nodamoney
NodaMoney provides a library that treats Money as a first class citizen and handles all the ugly bits like currencies and formatting.
Stars: ✭ 144 (+213.04%)
Mutual labels:  money, currencies
Django Prices
Django fields for the prices module
Stars: ✭ 135 (+193.48%)
Mutual labels:  money, currencies
stockholm
💵 Modern Python library for working with money and monetary amounts. Human friendly and flexible approach for development. 100% test coverage + built-in support for GraphQL and Protocol Buffers transports using current best-practices.
Stars: ✭ 26 (-43.48%)
Mutual labels:  money, currencies
Prices
Python price handling for humans.
Stars: ✭ 248 (+439.13%)
Mutual labels:  money, currencies
react-local-currency
💵 💴Shows the price of your services in the customer's currency 💶 💷
Stars: ✭ 21 (-54.35%)
Mutual labels:  money, currencies
Javamoney Lib
JavaMoney financial libraries, extending and complementing JSR 354
Stars: ✭ 104 (+126.09%)
Mutual labels:  money, currencies
Fixer
A foreign exchange rates and currency conversion API
Stars: ✭ 2,545 (+5432.61%)
Mutual labels:  money, currencies
latinum
Latinum is a framework for resource and currency calculations.
Stars: ✭ 109 (+136.96%)
Mutual labels:  money, currencies
CoinHive
A nice friendly simple and easly customizable GUI for coinhives javascript miner to embed onto websites so users of your site can interact with features of the miner on every single page this javascript miner is to help those who have problems with advertisements/advertising/ads popups banners mobile redirects malvertising/malware etc and provid…
Stars: ✭ 58 (+26.09%)
Mutual labels:  money
grouptabs
Mobile Web App to organize payments in dynamic groups of people.
Stars: ✭ 40 (-13.04%)
Mutual labels:  money
salary-negotiation-tech
Articles and posts on salary negotiation for devs/nerds/software engineers/tech people.
Stars: ✭ 53 (+15.22%)
Mutual labels:  money
querie
Compose Ecto query from the client side
Stars: ✭ 20 (-56.52%)
Mutual labels:  ecto

Monetized [Unmaintained]

Build Status Deps Status Inline docs

As a general rule, using floats to store money is a bad idea.

Enter Monetized. A library that aims to facilitate the handling of money through a safe way to store currency values and and providing abstractions to perform arithmetical operations on those values.

Monetized leverages Decimal's ability to safely handle arbitrary precision to perform calculations on money values.

A typical %Monetized.Money{} struct will contain a value in the shape of a Decimal struct and a currency (if any) as a string.

Requires elixir version 1.3.x or above as per ecto 2.x

Usage

Monetized also ships with a Ecto.Type that gives us an easier way to store money.

alias Monetized.Money

schema "transaction" do
  field :description, :string
  field :balance, Money, default: Money.zero

  timestamps
end

By doing this we're able to pass a %Money{} struct to the changeset and insert in the Repo since Ecto knows how to convert that struct into a primitive type to save and back when you read from it.

balance = Money.make("£ 100.50")
changeset = Transaction.changeset(%Transaction{}, %{description: "Invoice payment", balance: balance})

# Or

balance = %{value: "100.50", currency: "GBP"}
changeset = Transaction.changeset(%Transaction{}, %{description: "Invoice payment", balance: balance})

Check the docs for more.

Other usage

alias Monetized.Money
alias Monetized.Math

# Create with a string
iex> item_one = Money.make("£ 200.50")
#Money<200.50GBP>

# Or a float
iex> item_two = Money.make(10.25, [currency: "GBP"])
#Money<10.25GBP>

# Adding two moneys together
iex> Math.add(item_one, item_two)
#Money<210.75GBP>

# Or an integer
iex> balance = Money.make(100_000, [currency: "USD"])
#Money<100000.00USD>

# Substracting from money (currency inferred from balance)
iex> result = Math.sub(balance, 50_000)
#Money<50000.00USD>

# Getting the string representation
iex> Money.to_string(result, [currency_symbol: true])
"$ 50,000.00"

# You can also use `from_integer/2`, `from_float/2`, `from_decimal/2` and `from_string/2`
# respectively if the desired behavior is to raise when the amount is 
# not of the expected type.

# If either the symbol or the currency key is found within the string,
# that currency will be used. However, if a different currency is given in the
# options, it will take precedence.

iex> Money.from_string("£ 200")
#Money<200.00GBP>

iex> Money.from_string("200 EUR")
#Money<200.00EUR>

iex> Money.from_integer(200)
#Money<200.00>

iex> Money.from_float(200.50)
#Money<200.50>

iex> decimal = Decimal.new(10.25)
...> Money.from_decimal(decimal, currency: "EUR")
#Money<10.15EUR>

iex> Money.from_integer("10")
** (FunctionClauseError) no function clause matching in Monetized.Money.from_integer/2
    (monetized) lib/money.ex:204: Monetized.Money.from_integer("10", [])

Check the docs for more examples

Config

config :monetized, config: [
  delimiter: ",",
  separator: ".",
  currency: "USD",
  format: "%cs %n%s%d"
]

Installation

Add monetized to your list of dependencies in mix.exs:

def deps do
  [{:monetized, "~> 0.5.0"}]
end

TODO

  • New currencies can be added through the package's config
  • 1.0.0 ! yay!

Benchmarking

$ mix deps.get
$ MIX_ENV=bench mix compile
$ MIX_ENV=bench mix bench

Contributing

See CONTRIBUTING.md for details.

Licensing

See LICENSE.md

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].