Currencier Currency Converter 2 4 2
This is a Dart implementation of Money and Currency classes
Nov 26, 2020 Currencier is a converter of more than 180 currencies in all directions. A distinctive feature is elegant and modern design, easy to enter, clear and friendly interface. Currency converter for macOS 10.10 or later and enjoy it on your Mac. Currencier is a converter of more than 180 currencies in all directions. A distinctive feature is elegant and modern design, easy to enter, clear and friendly interface.
- Creating Currencies
- Allocation
Overview #
Money2 is a fork of LitGroup's Money package.
The aim of this fork is to improve the documentation and introduce a number of convenience methods to make it easier to work with Money.This package also changes some of the naming convention to provide a (hopefully) more intuiative api.
Key features of Money2:
- simple and expressive formating.
- simple parsing of monetary amounts.
- multi-currency support.
- intuitive maths operations.
- fixed precision storage to ensure precise calcuation.
- detailed documentation and extensive examples to get you up and running.
- pure dart implementation.
- Open Source MIT license.
- Using Money2 will make you taller.
The Money class stores the underlying values using a BigInt. The value is stored using the currencies' 'minor units' (e.g. cents).This allows for precise calculations as required when handling money.
Let's start with some examples:
The package use the following terms:
- Minor Units - the smallest unit of a currency e.g. cents.
- Major Units - the integer component of a currency - e.g. dollars
- code - the currency code. e.g. USD
- symbol - the currency symbol. e.g. '$'. It should be noted that not every currency has a symbol.
- pattern - a pattern used to control parsing and the display format.
- minorDigits - the number of minor Units (e.g. cents) which should be used when storing the currency.
- decimal separator - the character that separates the fraction part from the integer of a number e.g. '10.99'. This defaults to '.' but can be changed to ','
- thousands separator - the character that is used to format thousands (e.g. 100,000). Defaults to ',' but can be changed to '.'
Creating a Currency #
Before you can start creating Money instances you first need a Currency.
The Money2 package does not contain any 'built-in' Currency types. Instead you must create your own Currency instances as required.
Creating a Currency is simple:
You would normally create a single instance of a Currency and re-use that throughout your code base.
Registering a Currency #
To make your life easier we provide the Currencies class which is a singleton that allows you to register your currencies and quickly retrieve them from anywhere in your code.
Note: it is NOT a requirement to register a currency. You can just recreate and use currencies whenever and wherever you choose.
From version 1.4.0 we ship with a list of common currencies.
You can access the list of common currencies in the CommonCurrencies
class.You can either register individual Currency
s or register all of them at once:
Here is the list of currencies available in CommonCurrencies
Default format #
The Currency class also allows you to specify a default format which is used when parsing or formating a Money
instance.
Note: if you don't specify a pattern it defaults to 'S0.00'
You can also use the Money.format
method to define a specific format where required. See details below
Symbols #
A number of currency have different symbols, you can specify the symbol when creating the currency.
Separators #
Decimal Separator
Numbers use a decimal separator to separate the integer and factional component of a number.
In the english speaking world the period (.) is used as the decimal separator, however in large parts of the world the comma (,) is used as the decimal separator.
e.g.
$USD1,000.99 (one thousand dollars and 99 cents)
€EUR1.000,99 (one thousand euro and 99 cents)
Money2 use the English convention. To switch to the Euro style convention set the invertSeparators argument to true when creating a currency.
You will also need to provide an appropriate pattern.
Thousand Separator #
Numbers also use a thousands separator to help format large numbers by placing a separator every few digits.e.g.$100,000.00
In the english speaking world the comma (,) is used as the thousands separator however in large parts of the world the period (.) is used as the thousands separator.
Money2 use the English convention. To switch to the Euro style convention set the invertSeparators argument to true when creating a currency.
You will also need to provide an appropriate pattern.
Creating Money #
For you convience we provide a number of methods to create a Money
instance.
- Money.parse - parse a monetary string containing an amount.
- Money.fromInt - from a minorUnit (e.g. cents)
- Money.fromBigInt - from a minorUnit
- Money.from - from a num (int or double)
- Currency.parse - parse a monetary string assuming the currency
- Currencies.parse - parse a monetary amount and determine the currency from the embedded currency code.
The Money
variants all require you to pass in the Currency
.The Currency
variant requires only the monetary value.The Currencies
variant is able to determine the Currency
if the passed string amount contains a currency code.
The two most common methods are:
- Money.fromInt
- Currency.parse
Money.parse #
Parses a string containing a monetary value.
Money.fromInt
is faster if you already have the value represented as an integer in minor units.
The simplest variant of Money.parse
relies on the default pattern
ofthe passed currency.
You can also pass an explict pattern.
Currency.parse #
The simplest variant of Currency.parse
relies on the default pattern ofthe currency.
You can also pass an explict pattern.
Money.fromInt #
Money
can be instantiated by providing the amount in the minor units of thecurrency (e.g. cents):
Currencies.parse #
This method is extremely useful if you have a database/list of monetary amountsthat contain their currency code.'Currencies.parse' will create a Money
instance of the correct currency based on the currency code embedded in the monetary amount.
An exception will be thrown if the monetary amount does not include a currencycode.
Before you can use Currencies.parse
you must first register the listof Currency's
that you need to support.
If you try to create a Money
instance for an unregistered Currency
an UknownCurrencyException
will be thrown.
Formatting #
The money class provides a simple way of formatting currency using a pattern.
When you create a Currency instance you can provide a default format pattern which is used to formata Money instance when you call Money.toString()
.
In some cases you may however want to format a Money instances in a specific manner. In this case you can use:
Money.format(String pattern)
Formatting Patterns #
Note: the same patterns are used for both formatting and parsing monetary amounts.
The supported pattern characters are:
Examples:
Exchange Rates #
When manipulating monetary amounts you often need to convert between currencies.
Money2 provide a simple method to convert a Money
instance to anothercurrency using an exchange rate.
To converts a Money
instance into a target Currency
use the Money.exchangeTo
method.
To do this you need to define an exchange rate which is simply another Money
instance. That 'exchange rate' Money
instance is created with the target Currency
and having a monetary value which represents the exchange rate.
Example #
Lets say you have an invoice in Australian Dollars (AUD) whichyou need to convert to US Dollars (USD).
Start by google the exchange rate for AUD to USD.You are likely to find something similar to:
1 AUD = 0.68c USD
Which means that for each Australian Dollar you will recieve0.68 US cents. (AKA I'm not traveling to the USA this year).
To do the above conversion:
Comparison #
Equality operator () returns true
when both operands are in the samecurrency and have an equal amount.
Money values can be compared with the <
, <=
, >
, >=
operators, or the methodcompareTo()
from the interface Comparable<Money>
.
These operators and method compareTo()
can be usedonly between money values in the same currency. Runtime error will be thrownon any attempt to compare values in different currencies.
Currency Predicates #
To check that money value has an expected currency use the methodsisInCurrency(Currency)
and isInSameCurrencyAs(Money)
:
Value Sign Predicates #
To check if a money amount is a credit, a debit or zero, use predicates:
Money.isNegative
— returnstrue
only if amount is less than0
.Money.isPositive
— returnstrue
only if amount is greater than0
.Money.isZero
— returnstrue
only if amount is0
.
Arithmetic Operations #
The Money class is immutable, so each operation returns a new Money instance.
Money
provides the following arithmetic operators:
- unary
-()
+(Money)
-(Money)
*(num)
/(num)
Operators +
and -
must be used with operands in same currency, otherwiseArgumentError
will be thrown.
Operators *
, /
receive a num
as the second operand. Both operators useschoolbook rounding to round result up to a minorUnits of a currency.
Allocation #
Allocation According to Ratios #
Currencies Currency Converter 2 4 2 5
Let our company have made a profit of 5 cents, which has to be divided amongsta company (70%) and an investor (30%). Cents can't be divided, so We can'tgive 3.5 and 1.5 cents. If we round up, the company gets 4 cents, the investorgets 2, which means we need to conjure up an additional cent.
Xc Currency Converter
The best solution to avoid this pitfall is to use allocation accordingto ratios.
Currencies Currency Converter 2 4 24
Allocation to N Targets #
An amount of money can be allocated to N targets using allocateTo()
.
Money encoding/decoding #
API for encoding/decoding a money value enables an application to storevalues in a database or send over a network.
A money value can be encoded to any type. For example it can be codedas a string in the format like 'USD 5.00'.
Note: this is a trivial example and you would simply use the parse/format methodsto encode/decode from/to a string.
Encoding #
Decoding #
Name | Currency Converter Pro |
---|---|
Package | com.devnied.currency.pro |
Version | 2.5.0 |
Requires | Android4.1 |
Genre | Calculator Unit Converter |
Currency Converter for over 180 currencies with updated exchange rates and offline mode.
Download “Currency Converter” and get world's foreign currencies conversion rates.
Easy to use for conversion of many foreign currencies directly from the widget.
Add your personal favorite currency list.
Currency Converter Pro
• No Ads: does not contain any advertising
• Customizable widget to follow favorites currencies
• Material design: beautiful and user friendly application design
• Quick updates: fast and recurrent update, with new features
• Updated exchange rates: fresh, consistent and reliable exchange rate data
• Live and historical exchange rates for over 180+ world currencies
• Popular cryptocurrencies exchange rate like Bitcoin or Ethereum
• Offline mode No roaming fees and application keep working without an internet connection
• Search function to quickly add a new currency by country name
• Interactive historical currency charts from 1 day to 5 years
Currency rates are saved for offline use at every update so you can convert with the most accurate rates at all times.
Use it offline
- Stores the last updated rates
- Convert prices without internet access
What's news
New dark theme and improved Android 11 support.
We update the app regularly so we can make it better for you.
This version includes several bug fixes and performance improvements.