Percentage Calculation

Percentage Calculation

Math & Calculations Credits / request: 1

Calculates percent of, increase, decrease, ratio and percent change.

GET https://api.apikodu.com/api/v1/math/percentage
Documentation
Overview

Percentage calculations: of, increase, decrease, ratio, change.

Authentication

Every request requires the x-api-key header. Credits used and remaining quota are returned in response headers (x-api-credits-used, x-api-remaining-credits, x-rate-limit-*).

Request
GET https://api.apikodu.com/api/v1/math/percentage?value=80&rate=25&mode=of
Query string.
Parameters
Name Type Required Default Options Description
value number * Required — — Main number.
rate number Optional — — Percent for of/increase/decrease.
mode string Optional of of increase decrease ratio change of: percent of. increase/decrease: add/subtract. ratio: value as % of valueTo. change: percent change.
valueTo number Optional — — Second number for ratio and change.
Response
Name Type Description
value number Result. of: percent amount. increase/decrease: new value. ratio/change: percent.
rate number of/increase/decrease: input rate. ratio/change: computed percent.
difference number increase/decrease: absolute difference. change: valueTo − value. May be 0 for other modes.
mode string Applied mode: of, increase, decrease, ratio, change.
Errors
HTTP code Description
400 -241 value is required. of/increase/decrease need rate; ratio/change need valueTo. Number may be out of range.
400 -242 mode is not of, increase, decrease, ratio or change.
401 -100 x-api-key is missing, empty, malformed, inactive, banned, expired, IP-restricted, or not allowed for this API.
429 -221 Per-minute request limit exceeded. Response headers: x-rate-limit-limit, x-rate-limit-remaining, x-rate-limit-reset.
429 — Package credit quota cannot cover this request. Body may be { error, limit, currentUsage, requestCost } (no code field).
500 -1 Unexpected server error. message is a generic error text without technical details.
Notes
  • Success body is { data: { ... } }. Error body is { code, message }. code is an ApiResponseCode enum value (negative integer).

Sample response

{
  "data": {
    "value": 20.0,
    "rate": 25.0,
    "difference": 20.0,
    "mode": "of"
  }
}

Code samples

  
      const response = await fetch('https://api.apikodu.com/api/v1/math/percentage', {
        method: 'GET',
        headers: {
          'x-api-key': 'YOUR_API_KEY'
        }
      });

      const data = await response.json();
      console.log(data);
  
  
      import requests

      headers = {
          'x-api-key': 'YOUR_API_KEY'
      }

      response = requests.get('https://api.apikodu.com/api/v1/math/percentage', headers=headers)
      print(response.json())
  
  
      using var client = new HttpClient();
      client.DefaultRequestHeaders.Add("x-api-key", "YOUR_API_KEY");

      var response = await client.GetStringAsync("https://api.apikodu.com/api/v1/math/percentage");
      Console.WriteLine(response);
  
  
      $response = file_get_contents('https://api.apikodu.com/api/v1/math/percentage', false, stream_context_create([
          'http' => [
              'header' => "x-api-key: YOUR_API_KEY"
          ]
      ]));

      print_r(json_decode($response, true));
  
  
      curl -X GET 'https://api.apikodu.com/api/v1/math/percentage' \
        -H 'x-api-key: YOUR_API_KEY'
  

Start building in minutes

Create a free account, get your API key and send your first request in minutes.

Get started free