|
1 | | -# 📊 Percentify |
| 1 | +# 📊 Percentify |
2 | 2 |
|
3 | | -**Percentify** — because fractions are overrated 😎 |
4 | | -A ridiculously tiny Python library for turning *"part of a whole"* into neat percentages without the brain math. |
| 3 | +[](https://pypi.org/project/percentify/) |
| 4 | +[](https://pypi.org/project/percentify/) |
| 5 | +[](LICENSE) |
| 6 | +[](https://github.com/data-centt/percentify/actions/workflows/python-app.yml) |
| 7 | + |
| 8 | +**Percentify** — a tiny Python helper that turns *"part of a whole"* into a clean percentage. |
| 9 | +Stop typing `(part / whole) * 100` and worrying about division by zero. |
5 | 10 |
|
6 | 11 | --- |
7 | 12 |
|
8 | | -## ✨ Features |
9 | | -- ✅ Calculate the percentage of any two numbers |
10 | | -- ✅ Safe divide (returns `0.0` if the denominator is zero — no more crashes 🎉) |
11 | | -- ✅ Control the number of decimal places |
12 | | -- ✅ Zero dependencies, ultra-lightweight |
| 13 | +## ✨ What It Does |
13 | 14 |
|
14 | | ---- |
| 15 | +Percentify gives you a single function: |
15 | 16 |
|
16 | | -## 📦 Installation and Use Case |
| 17 | +- Calculates what percentage one number is of another. |
| 18 | +- Handles divide-by-zero safely (returns 0.0 instead of crashing). |
| 19 | +- Lets you choose how many decimal places to round to. |
| 20 | +- Has zero dependencies — just pure Python. |
17 | 21 |
|
18 | | -```bash |
| 22 | +## 📦 Installation |
| 23 | +``` |
19 | 24 | pip install percentify |
| 25 | +``` |
20 | 26 |
|
| 27 | +### Usage |
| 28 | +``` |
21 | 29 | from percentify import percent |
22 | | -percent(15, 30) == 50% |
| 30 | +
|
| 31 | +# Basic usage |
| 32 | +percent(50, 200) # → 25.0 |
| 33 | +
|
| 34 | +# Handles fractions |
| 35 | +percent(1, 3) # → 33.33 |
| 36 | +
|
| 37 | +# Safe when dividing by zero |
| 38 | +percent(5, 0) # → 0.0 |
| 39 | +
|
| 40 | +# Custom decimals |
| 41 | +percent(7, 9, 4) # → 77.7778 |
| 42 | +``` |
| 43 | + |
| 44 | +### 🛠️ How It Works |
| 45 | + |
| 46 | +The library is intentionally simple — just one function: |
23 | 47 | ``` |
| 48 | +def percent(part: float, whole: float, decimals: int = 2) -> float: |
| 49 | + if whole == 0: |
| 50 | + return 0.0 |
| 51 | + return round((part / whole) * 100, decimals) |
| 52 | +``` |
| 53 | +That’s it. Clean, safe, and ready to use anywhere you need percentages in your code. |
| 54 | + |
| 55 | +# 🤝 Contributing |
| 56 | + |
| 57 | +Contributions are welcome! |
| 58 | +- If you have an idea (extra helpers, bug fixes, or better docs): |
| 59 | +- Fork this repo |
| 60 | +- Create a branch |
| 61 | +- Commit your changes |
| 62 | +- Open a pull request |
24 | 63 |
|
| 64 | +I try to keep it tiny on purpose, so discuss big new features first. |
0 commit comments