Skip to main content

A micro-library to easily calculate percentage between two numbers.

Project description

% Percentify %

PyPI version Python Versions License Build Status

Percentify — a tiny Python helper that turns "part of a whole" into a clean percentage.
Stop typing (part / whole) * 100 and worrying about division by zero.


✨ What It Does

Percentify gives you a single function:

  • Calculates what percentage one number is of another.
  • Handles divide-by-zero safely (returns 0.0 instead of crashing).
  • Lets you choose how many decimal places to round to.
  • Has zero dependencies — just pure Python.

📦 Installation

pip install percentify

Usage

from percentify import percent

# Basic usage
percent(50, 200)          # → 25.0

# Handles fractions
percent(1, 3)             # → 33.33

# Safe when dividing by zero
percent(5, 0)             # → 0.0

# Custom decimals
percent(7, 9, 4)          # → 77.7778

🛠️ How It Works

The library is intentionally simple — just one function:

def percent(part: float, whole: float, decimals: int = 2) -> float:
    if whole == 0:
        return 0.0
    return round((part / whole) * 100, decimals)

That’s it. Clean, safe, and ready to use anywhere you need percentages in your code.

🤝 Contributing

Contributions are welcome!

  • If you have an idea (extra helpers, bug fixes or an idea):
  • Fork this repo
  • Create a branch
  • Commit your changes
  • Open a pull request

I try to keep it tiny on purpose, to discuss big new features first.

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

percentify-0.1.3.tar.gz (6.6 kB view details)

Uploaded Source

Built Distribution

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

percentify-0.1.3-py3-none-any.whl (7.0 kB view details)

Uploaded Python 3

File details

Details for the file percentify-0.1.3.tar.gz.

File metadata

  • Download URL: percentify-0.1.3.tar.gz
  • Upload date:
  • Size: 6.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.8

File hashes

Hashes for percentify-0.1.3.tar.gz
Algorithm Hash digest
SHA256 ed4b4aec3b6cf6809372e2effe92dc6c9ed7bed9f798636995e5eaf4c7e368fb
MD5 399b816871355116eb9476e0e1bbba17
BLAKE2b-256 f8e0612491ae93156d86ab2cd587ac90264221049bb58982ac9dca28db3f6c0a

See more details on using hashes here.

File details

Details for the file percentify-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: percentify-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 7.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.8

File hashes

Hashes for percentify-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 0aa4199f92d736ffa7077e454480fe953732370e0b7e1176b1f292bb5f5b10d4
MD5 5765112cb262a94d7f1df7c0dbc19eb6
BLAKE2b-256 c53c3ffd83f97b2a7141b6c82e36fed32c0ca0aed4cec482470aef8c4b908d1a

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