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

Project details


Download files

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

Files for nh-currency, version 1.0.1
Filename, size File type Python version Upload date Hashes
Filename, size nh_currency-1.0.1-py3-none-any.whl (12.0 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size nh-currency-1.0.1.tar.gz (10.7 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page