Asterisk provides the MATH function to do mathematical operations from dialplan. It allows to perform mathematical operations between two parameters.

The syntax for math function is

MATH(expression,type)

The operators supported by math function are

+,-,/,*,%,<<,>>,^,AND,OR,XOR,<,>,<=,>=,==

The possible output types are

f : float,

i: int,

h: hex ,

c: char

if type int is used for the math function, all the decimals from output will be removed.

Examples

division with output type as float

exten => 111,1,Set(i=${MATH(30/60,f)})

output : 0.500000

 

division with output type as integer

exten => 111,1,Set(i=${MATH(30/60,i)})

output : 0 // integer type removes all the decimal part from output

 

modular division with output type as integer

exten => 111,1,Set(i=${MATH(1%2,i)})

output : 1