Percentage calculator API: of, is, change, apply, reverse
Five everyday percentage questions in one endpoint. Ask what 20% of 50 is, what percent 15 is of 60, how much 80→100 changed, what 200 becomes after +15%, or what the original was before a markup.
/v1/percent?mode=of&percent=20&of=50 returns JSON. No key, CORS on, 60 requests a minute./v1/percent
Percentage calculator: of, is, change, apply, reverse. Change the values and press Send request to call the live API.
Parameters
| Name | Type | What it does | Default |
|---|---|---|---|
mode required | string | of | is | change | apply | reverse | — |
percent | string | Percent value (modes of / apply / reverse); trailing % ok | — |
of | string | Whole amount (mode=of) | — |
part | string | Part amount (mode=is) | — |
whole | string | Whole amount (mode=is) | — |
from | string | Start value (mode=change) | — |
to | string | End value (mode=change) | — |
value | string | Starting value (mode=apply) | — |
result | string | Value after the change (mode=reverse) | — |
Example
Request:
GET https://api.oddlathe.com/v1/percent?mode=of&percent=20&of=50
Response (generated by the real code when these docs were last built; random or time-based values will differ for you):
{
"mode": "of",
"percent": 20,
"of": 50,
"result": 10,
"formula": "20% of 50 = 10"
}
Code examples
curl 'https://api.oddlathe.com/v1/percent?mode=of&percent=20&of=50'const params = new URLSearchParams({
mode: "of",
percent: "20",
of: "50"
});
const res = await fetch(`https://api.oddlathe.com/v1/percent?${params}`);
if (!res.ok) throw new Error((await res.json()).error.message);
const data = await res.json();
console.log(data);import json, urllib.parse, urllib.request
params = urllib.parse.urlencode({"mode": "of", "percent": "20", "of": "50"})
url = "https://api.oddlathe.com/v1/percent?" + params
# Send a User-Agent: the edge network refuses Python's default one.
req = urllib.request.Request(url, headers={"User-Agent": "my-script/1.0"})
with urllib.request.urlopen(req, timeout=10) as r:
data = json.load(r)
print(data)When it's useful
- Checkout / invoice scripts that need markups and discounts without a spreadsheet
- Normalising "was £80, now £100" into a signed percent change for reports
- Recovering a pre-tax or pre-markup price from the final figure
- Teaching the difference between "20% of" and "percent change"
Good to know
modeis required:of,is,change,applyorreverse.mode=ofneedspercentandof(the whole). Returnsresult.mode=isneedspartandwhole. Returnspercent.wholemust not be zero.mode=changeneedsfromandto. Returnspercent_change,absolute_changeanddirection. Percent change is (to − from) ÷ from × 100, so 80→100 is +25%.frommust not be zero.mode=applyneedsvalueandpercent(positive increases, negative decreases). Returnsresult.mode=reverseneedsresult(the value after the change) andpercent. Returnsoriginal. A −100% change cannot be reversed.- A trailing
%on number params is accepted and stripped. Pure maths on the query string; nothing is stored. - Browser UI: Tooltern percentage calculator (same maths, nothing leaves your device).
Five percentage questions: what is X% of Y, X is what % of Y, percent change from A to B, apply ±% to a value, or recover the original before a % change. Pure maths; nothing is stored.
Errors
Errors are JSON like {"error": {"code": "…", "message": "…"}}. The ones this endpoint can return:
missing_param(400): a required parameter is missing or emptybad_param(400): a value is the wrong type or out of range (the message says which)rate_limited(429): over 60 requests a minute; wait for Retry-After seconds
Questions
Why is 80→100 a 25% increase, not 20%?
Percent change is relative to the starting value: (100 − 80) ÷ 80 = 0.25. The 20-point gap is 20% of 100, which answers a different question.
Can I undo a −100% discount?
No. Multiplying by zero leaves no information about the original, so reverse returns bad_param.
Is anything stored?
Never. Pure maths on the query string.
Related endpoints
/v1/unitsConvert length, mass, temperature, data-size or data-rate units/v1/date/diffAge, duration and ISO week maths between two dates/v1/colorColour formats (hex, RGB, HSL, OKLCH) and WCAG contrast
Prefer a page to an API?
- Percentage calculator (of, is, change, apply, reverse) on Tooltern: same job, nothing leaves your browser.
Published · OpenAPI 3.1 spec · Limits and privacy