Work in progress
This documentation page is currently work in progress.
Not all existing DecAPI endpoints are documented here yet. For the currently active documentation, please visit docs.decapi.me.
Evaluate math expression
Performs a mathematic operation based on the expression passed to the endpoint.
Keep in mind to properly URL-encode exp
, so that certain characters are handled correctly.
Thanks to mathjs for providing the library / API for this endpoint.
Handling addition (plus) properly
Especially important with the +
(plus) character. If the +
character is passed as-is to the URL, it will be interpreted as a space character.
For the API to consider +
as an actual "plus" / addition, it needs to be URL-encoded as %2B
.
If you're allowing your viewers to use this as a command in your Twitch chat, then there are some bots that have command variables to properly handle this, such as:
The examples at the bottom of this documentation page try to use the correct bot variables for each bot, but the bots listed above are the only ones I know of that will properly encode the +
character unless done manually.
Endpoint URL
https://decapi.me/math?exp=369%2B51
Query parameters
exp
- Required - The mathematic expression to receive the result from.round
- Optional - Round to the specified number of decimal places.- If specified with 0 or below, or with no value, the result will be rounded to the nearest whole number.
Examples
- 369 + 51: https://decapi.me/math?exp=369%2B51
- 369.122222 + 51.57474769: https://decapi.me/math?exp=369.122222%2B51.57474769
- 369.122222 + 51.57474769 rounded to 1 decimal place: https://decapi.me/math?exp=369.122222%2B51.57474769&round=1
- 369.122222 + 50.57474769 rounded to a whole number: https://decapi.me/math?exp=369.122222%2B50.57474769&round=0
Examples for bots
Nightbot
Note: Nightbot will automatically convert variables, such as$(channel)
or $(touser)
to the correct channel name / username, when the command is used.
You do not have to change those variables.
-
Evaluate expression:
$(urlfetch https://decapi.me/math?exp=$(querystring))
Fossabot
Note: Fossabot will automatically convert variables, such as$(channel)
or $(user.login)
to the correct channel name / username, when the command is used.
You do not have to change those variables.
-
Evaluate expression:
$(customapi https://decapi.me/math?exp=$(querystring))
StreamElements
Note: StreamElements will automatically convert variables, such as${channel}
or ${touser}
to the correct channel name / username, when the command is used.
You do not have to change those variables.
-
Evaluate expression:
${customapi.https://decapi.me/math?exp=${queryescape ${1:}}}
Streamlabs Chat Bot
Note: Streamlabs Chat Bot will automatically convert variables, such as$mychannel
or $touserid
to the correct channel name / username, when the command is used.
You do not have to change those variables.
-
Evaluate expression:
$readapi(https://decapi.me/math?exp=$msg)
Streamlabs Cloudbot
Note: Streamlabs Cloudbot will automatically convert variables, such as{channel.name}
or {touser.name}
to the correct channel name / username, when the command is used.
You do not have to change those variables.
-
Evaluate expression:
{readapi.https://decapi.me/math?exp={1:100}}
Deepbot
Note: Deepbot will automatically convert variables, such as@stream@
or @user@
to the correct channel name / username, when the command is used.
You do not have to change those variables.
-
Evaluate expression:
@customapi@[https://decapi.me/math?exp=@target@]
PhantomBot
Note: PhantomBot will automatically convert variables, such as(channelname)
or (touser)
to the correct channel name / username, when the command is used.
You do not have to change those variables.
-
Evaluate expression:
(customapi https://decapi.me/math?exp=(echo))