3.0.0 • Published 1 year ago

@heartinz/currency_subunit_converter v3.0.0

Weekly downloads
-
License
ISC
Repository
-
Last release
1 year ago

Currency Converter Utility

A lightweight utility for handling currency conversions between major currencies and their subunits. This package uses Big.js for precise arithmetic operations.

Features

  • Convert amounts between currencies and their subunits.
  • Supports rounding to two decimal places.
  • Handles major currencies including INR, USD, GBP, EUR, and JPY.

Installation

To install the package, use npm:

npm install @heartinz/currency-converter


import CurrencyConverter from '@heartinz/currency-converter';

/**
 * Converts a given amount in base currency to its subunit equivalent.
 * 
 * @param {number} amount - The amount in base currency (e.g., 123.45).
 * @param {string} currencyCode - The currency code ('INR', 'USD', 'GBP', 'EUR', 'JPY').
 * @returns {number} - The amount converted to subunits (e.g., Paise, Cents).
 */
CurrencyConverter.toSubunit(123.45, 'INR'); // 12345

/**
 * Converts a given amount in subunits to its base currency equivalent.
 * 
 * @param {number} amount - The amount in subunits (e.g., 12345).
 * @param {string} currencyCode - The currency code ('INR', 'USD', 'GBP', 'EUR', 'JPY').
 * @returns {number} - The amount converted to base currency.
 */
CurrencyConverter.toCurrency(12345, 'INR'); // 123.45



## Supported Currencies

| Currency Code | Base Unit  | Subunit  | Notes                     |
|---------------|------------|----------|---------------------------|
| INR           | Rupee      | Paise    | 1 INR = 100 Paise         |
| USD           | Dollar     | Cents    | 1 USD = 100 Cents         |
| GBP           | Pound      | Pence    | 1 GBP = 100 Pence         |
| EUR           | Euro       | Cents    | 1 EUR = 100 Cents         |
| JPY           | Yen        | None     | No subunits for JPY       |
3.0.0

1 year ago

2.1.4

1 year ago

2.1.3

1 year ago

2.1.2

1 year ago

2.1.1

1 year ago

2.1.0

1 year ago

2.0.0

1 year ago