Skip to main content

A python library to convert currency, prettify price and get various currency info

Project description

A simple currency module to:

  • Retrive various info about currency

  • Format currency price

  • Convert between currencies

Requirements

  • python3

  • Internet connection (optional)

Installation

$ pip install nh-currency

Usage

import currency

Get currency name

currency.name('USD')
currency.name('USD', plural=True)
'US Dollar'
'US dollars'

Symbol

currency.symbol('CAD')
currency.symbol('CAD', native=False)
currency.symbol('NOK')
currency.symbol('NOK', native=False)
'$'
'CA$'
'kr'
'Nkr'

Number of decimal digits

currency.decimals('USD')
currency.decimals('JPY')
2
0

Round to the maximum decimal digits

currency.rounding(100.115735, 'USD')
currency.rounding(2253.12309, 'ISK')
100.12
2253

Currency increment used for rounding

currency.roundto('USD')
currency.roundto('CHF')
0
0.05

Format currency

currency.pretty(10050000.2394, 'USD')
currency.pretty(10050000.2394, 'USD', trim=True)
currency.pretty(10050000.2394, 'USD', abbrev=False)
'$10,050,000.2394'
'$10,050,000.24'
'10,050,000.2394 USD'

Convert to other currency

currency.convert('USD', 'EUR')
currency.convert('USD', 'EUR', 2)
currency.convert('JPY', 'AUD', 100)
0.815797
1.631594
1.1759

Currency info

currency.info('USD')
# Output has been formatted for representation purpose
{
    'symbol': '$',
    'name': 'US Dollar',
    'symbol_native': '$',
    'decimal_digits': 2,
    'rounding': 0,
    'code': 'USD',
    'name_plural': 'US dollars'
}

Testing

$ cd .../py-currency
$ python -m unittest

Resources

https://gist.github.com/Fluidbyte/2973986

https://www.wikipedia.org/

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nh-currency-1.0.1.tar.gz (10.7 kB view hashes)

Uploaded Source

Built Distribution

nh_currency-1.0.1-py3-none-any.whl (12.0 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page