Skip to main content

A Python library for currency redenomination

Project description

RedenPy

License: MIT

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, and str inputs.
  • 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, or Decimal.
  • Accurate Calculations: Uses the Decimal type 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


Download files

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

Source Distribution

redenpy-0.0.1.tar.gz (5.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

redenpy-0.0.1-py3-none-any.whl (5.4 kB view details)

Uploaded Python 3

File details

Details for the file redenpy-0.0.1.tar.gz.

File metadata

  • Download URL: redenpy-0.0.1.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

Hashes for redenpy-0.0.1.tar.gz
Algorithm Hash digest
SHA256 6dcfecb87ab4362477cdc91a5b4495d5ad8dd6e404d7290ef2c9234f00c79f9b
MD5 3e165fe7e1948855b1cb7ba879548b1d
BLAKE2b-256 071a23e42c0ba00d06d6c9fce76365e9a57425cbf3b07fc3bdeb4c3b8ea38b08

See more details on using hashes here.

File details

Details for the file redenpy-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: redenpy-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 5.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.2

File hashes

Hashes for redenpy-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 43e717bedc73367d955bfdd631a1c60836d1cc11a298ab290b9e19f9e834f662
MD5 88868c161355436e77520c381885ed82
BLAKE2b-256 d1c3d9452c88e2fe99bb06ada485bf325015e685b0e701a1296649b230fb91b5

See more details on using hashes here.

Supported by

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