A Python library for currency redenomination
Project description
RedenPy
A simple, robust Python utility for currency redenomination.
RedenPy is designed to parse various money formats—including strings with currency symbols and different decimal/thousand separators—and apply a redenomination by a specified number of digits (e.g., converting 1,000,000 to 1,000).
✨ Features
- Handles Multiple Input Types: Accepts
int,float,Decimal, andstrinputs. - Robust String Parsing: Automatically cleans currency symbols (
$,Rp,€, etc.) and non-numeric characters. - International Format Support: Intelligently parses both US-style (
1,000.00) and EU-style (1.000,00) number formats. - Flexible Output: Returns the redenominated value as a
str,int,float, orDecimal. - Accurate Calculations: Uses the
Decimaltype internally for all calculations to avoid floating-point errors.
📦 Installation
Install RedenPy directly from PyPI:
pip install redenpy
🚀 Quick Start
from redenpy.core import RedenPy
# 1. Initialize the redenominator
# We want to remove 3 digits (e.g., 1,000 -> 1)
rd = RedenPy(digit=3, rule=None) # 'rule' is reserved for future rounding logic
# 2. Perform redenomination on various inputs
# --- Example 1: Handling International String Formats ---
val_str_us = "$ 1,575,505.75" # Dot as decimal
val_str_eu = "€ 1.575.505,75" # Comma as decimal
# Returns a 'Decimal' object
new_val_us = rd.redenomination(val_str_us, output_type=Decimal)
new_val_eu = rd.redenomination(val_str_eu, output_type=Decimal)
print(f"'{val_str_us}' -> {new_val_us}")
# Output: '$ 1,575,505.75' -> 1575.51
print(f"'{val_str_eu}' -> {new_val_eu}")
# Output: '€ 1.575.505,75' -> 1575.51
# --- Example 2: Controlling Output Type ---
old_val = 1575800
# Get a formatted string with fractions
val_str = rd.redenomination(old_val, fractional=True, output_type=str)
print(f"{old_val} -> '{val_str}' (as string)")
# Output: 1575800 -> '1575,80' (as string)
# Get an integer (truncates the decimal)
val_int = rd.redenomination(old_val, output_type=int)
print(f"{old_val} -> {val_int} (as integer)")
# Output: 1575800 -> 1575 (as integer)
# Get a float
val_float = rd.redenomination(old_val, output_type=float)
print(f"{old_val} -> {val_float} (as float)")
# Output: 1575800 -> 1575.8 (as float)
📖 API Reference
RedenPy(digit, rule)
Initializes the redenomination class.
- digit (int): The number of digits to remove (e.g., 3 for 1,000 -> 1). This is equivalent to dividing by $10^{digit}$.
- rule (any): A parameter intended for future, more complex rounding rules (e.g., specific central bank regulations). Note: This parameter is not currently used in the logic. All calculations default to ROUND_HALF_UP to 2 decimal places.
redenomination(money, fractional=False, output_type=str)
Performs the redenomination on a given money value.
-
money (str | int | float | Decimal): The amount to convert.
-
fractional (bool): This parameter only affects the output_type=str.
- True: Returns the value with a fractional part, separated by a comma (e.g., "1575,51").
- False: Returns only the whole number part (e.g., "1575").
-
output_type (type): The desired return type for the converted value.
- str: Returns a formatted string. Behavior is controlled by fractional.
- Decimal: Returns the redenominated value as a Decimal object, rounded to 2 decimal places.
- float: Returns the redenominated value as a float.
- int: Returns the redenominated value as an int (note: this truncates any decimal part after rounding, e.g., 1575.51 becomes 1575).
🤝 Contributing
Contributions are welcome! Please feel free to open an issue or submit a pull request.
⚖️ License
This project is licensed under the MIT License - see the LICENSE file for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file redenpy-0.0.2.tar.gz.
File metadata
- Download URL: redenpy-0.0.2.tar.gz
- Upload date:
- Size: 5.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9274e59c1f13433335a53e77d1c2c69ea387cde7212248a60ad08a18b55bc29f
|
|
| MD5 |
3da618a7ab633d334445f5429919708e
|
|
| BLAKE2b-256 |
beeca2abae5a58f3ddf07bf679d26a047984c4c29896ee5d94a9a04a1e212700
|
File details
Details for the file redenpy-0.0.2-py3-none-any.whl.
File metadata
- Download URL: redenpy-0.0.2-py3-none-any.whl
- Upload date:
- Size: 5.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c0de5562d40d362c7baf89f081965d0b638b59ef26c2330c553289227257f710
|
|
| MD5 |
db6dc2c9494624d3f272d3b53ba657af
|
|
| BLAKE2b-256 |
6cf71da0e20d504e8ae940c75feed81d495d55dd4cd80d2d43a23ec79ab88c54
|