Percentage Calculator

Percentage Calculator API

Finance

Work out X% of a number, what percent one number is of another, the percentage change between two values, or add and subtract a percentage, with the formula shown.

Authentication

Send your API key as a Bearer token in the Authorization header (Authorization: Bearer YOUR_API_KEY), or in an X-API-Key header.

Rate Limit

120 requests per minute

Endpoints

2 endpoints available

Overview

Pick an operation and send the fields it needs:

  • percent-of: what is percent% of value?
  • what-percent: part is what percent of whole?
  • percent-change: the change from from to to, as a percentage of the starting value. A change from -50 to -25 is a 50% increase. The response also has percentDifference, which compares the two values with their average, for when neither is the starting point.
  • add-percent: value increased by percent%, for tax or markup.
  • subtract-percent: value decreased by percent%, for a discount.

Notes

  • Results have floating-point noise removed (rounded to 10 decimal places), so 7% of 1000 is 70, not 70.00000000000001.
  • what-percent with a whole of 0 and percent-change from 0 have no answer and return a 400 error.
  • Numbers can be negative. Values are limited to 1e15 in size.

Endpoints

POST
https://opentools.ca/api/v1/tools/percentage-calculator
Solve common percentage questions

Request Body

Content-Type: application/json

ParameterTypeRequiredDescription
operation
string
Enum: percent-of, what-percent, percent-change, add-percent, subtract-percent
Required
Which question to answer.
percent
number
OptionalThe percentage. Used by percent-of, add-percent and subtract-percent.
value
number
OptionalThe number to work on. Used by percent-of, add-percent and subtract-percent.
part
number
OptionalThe part. Used by what-percent.
whole
number
OptionalThe whole, not 0. Used by what-percent.
from
number
OptionalThe starting value, not 0. Used by percent-change.
to
number
OptionalThe new value. Used by percent-change.

Response Example

{
  "success": true,
  "operation": "percent-of",
  "percent": 20,
  "value": 150,
  "result": 30
}

Error Codes

400
Bad Request - A field is missing or invalid. The response lists each problem.
401
Unauthorized - Missing or invalid API key
403
Forbidden - The API key is inactive or expired, or the request IP is not allowed
405
Method Not Allowed - This endpoint accepts GET and POST only
429
Too Many Requests - Rate limit exceeded (120 requests per minute per API key)
500
Internal Server Error
GET
https://opentools.ca/api/v1/tools/percentage-calculator
Solve common percentage questions. Same fields as the POST body, sent as query parameters.

Query Parameters

ParameterTypeRequiredDescription
operation
string
Enum: percent-of, what-percent, percent-change, add-percent, subtract-percent
Required
Which question to answer.
percent
number
OptionalThe percentage. Used by percent-of, add-percent and subtract-percent.
value
number
OptionalThe number to work on. Used by percent-of, add-percent and subtract-percent.
part
number
OptionalThe part. Used by what-percent.
whole
number
OptionalThe whole, not 0. Used by what-percent.
from
number
OptionalThe starting value, not 0. Used by percent-change.
to
number
OptionalThe new value. Used by percent-change.

Response Example

{
  "success": true,
  "operation": "percent-of",
  "percent": 20,
  "value": 150,
  "result": 30
}

Error Codes

400
Bad Request - A field is missing or invalid. The response lists each problem.
401
Unauthorized - Missing or invalid API key
403
Forbidden - The API key is inactive or expired, or the request IP is not allowed
405
Method Not Allowed - This endpoint accepts GET and POST only
429
Too Many Requests - Rate limit exceeded (120 requests per minute per API key)
500
Internal Server Error

Code Examples

# What is 20% of 150
curl -X POST https://opentools.ca/api/v1/tools/percentage-calculator \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "operation": "percent-of",
  "percent": 20,
  "value": 150
}'

# Percentage change from 80 to 100
curl -X POST https://opentools.ca/api/v1/tools/percentage-calculator \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "operation": "percent-change",
  "from": 80,
  "to": 100
}'

# The same request as a GET with query parameters
curl "https://opentools.ca/api/v1/tools/percentage-calculator?operation=percent-of&percent=20&value=150" \
  -H "Authorization: Bearer YOUR_API_KEY"

Ready to get started?

Create an API key to start using the Percentage Calculator API.

Rather use it in your browser? Open the Percentage Calculator