Skip to main content

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

Project description

% Percentify %

PyPI Downloads 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;

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.4.tar.gz (6.9 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.4-py3-none-any.whl (7.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: percentify-0.1.4.tar.gz
  • Upload date:
  • Size: 6.9 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.4.tar.gz
Algorithm Hash digest
SHA256 c585885fb61bf59fedcbc6f49f8a2871abc1af34862c18aac77c826eafd1d006
MD5 6bd5985ce72233b2ee07b97109db9c07
BLAKE2b-256 8b5cfe51829472b0e7921d4cb4f05f792531cdc9074c4fd8b6bf325943678897

See more details on using hashes here.

File details

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

File metadata

  • Download URL: percentify-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 7.2 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.4-py3-none-any.whl
Algorithm Hash digest
SHA256 bfd428fd7c48ae3c7644f5933a04e963b3eec891ddc4792c1c62bc9d23ed0d77
MD5 3a6a7409db8c0df78a365426194c0d9c
BLAKE2b-256 39c5ce0af2e99b31bb1593a4cdbf07a6b1733b3b79f7bfc34c44a99ec274af0f

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