# Performing math functions in OpenSIPs Classic List Threaded 5 messages Open this post in threaded view
|

## Performing math functions in OpenSIPs

 Hello List, Im trying to do some math functions, ive tried a few different ways and get either invalid string operands or no value in right expression, ive tried the following: \$avp(i:70) is set to say .005 \$avp(i:55) = \$avp(i:70) * (6 / 100); \$avp(i:55) = (\$avp(i:70) * (6 / 100)); \$avp(i:55) = \$avp(i:70) * 6 / 100; \$avp(i:55) = \$avp(i:70) * .006; \$avp(i:55) = (\$avp(i:70) * .006); Im sure I tried a few more to, but basically i want to take a AVP then multiply it by a number and get a result, this will be a decimal like 0.00234 Any suggestions? Thanks _______________________________________________ Users mailing list [hidden email] http://lists.opensips.org/cgi-bin/mailman/listinfo/users
Open this post in threaded view
|

## Re: Performing math functions in OpenSIPs

 Hi Brad, The arithmetic ops do work only with integer values (no floats). Also be sure that the assignment to the avp you use was done as integer:     \$avp(i:1) = 3 ; and not like:     \$avp(i:1) = "3" ; Regards, Bogdan Brad Bendy wrote: > Hello List, > > Im trying to do some math functions, ive tried a few different ways > and get either invalid string operands or no value in right > expression, ive tried the following: > > \$avp(i:70) is set to say .005 > > \$avp(i:55) = \$avp(i:70) * (6 / 100); > \$avp(i:55) = (\$avp(i:70) * (6 / 100)); > \$avp(i:55) = \$avp(i:70) * 6 / 100; > \$avp(i:55) = \$avp(i:70) * .006; > \$avp(i:55) = (\$avp(i:70) * .006); > > Im sure I tried a few more to, but basically i want to take a AVP then > multiply it by a number and get a result, this will be a decimal like > 0.00234 > > Any suggestions? > > Thanks > > ------------------------------------------------------------------------ > > _______________________________________________ > Users mailing list > [hidden email] > http://lists.opensips.org/cgi-bin/mailman/listinfo/users>   -- Bogdan-Andrei Iancu www.voice-system.ro _______________________________________________ Users mailing list [hidden email] http://lists.opensips.org/cgi-bin/mailman/listinfo/users
Open this post in threaded view
|

## Re: Performing math functions in OpenSIPs

Hi,

That makes since now, we had a float actually. At this time no way to work with floats at all right?

Thanks

On Thu, 2010-03-04 at 21:10 +0200, Bogdan-Andrei Iancu wrote:
```Hi Brad,

The arithmetic ops do work only with integer values (no floats). Also be
sure that the assignment to the avp you use was done as integer:
\$avp(i:1) = 3 ;
and not like:
\$avp(i:1) = "3" ;

Regards,
Bogdan

> Hello List,
>
> Im trying to do some math functions, ive tried a few different ways
> and get either invalid string operands or no value in right
> expression, ive tried the following:
>
> \$avp(i:70) is set to say .005
>
> \$avp(i:55) = \$avp(i:70) * (6 / 100);
> \$avp(i:55) = (\$avp(i:70) * (6 / 100));
> \$avp(i:55) = \$avp(i:70) * 6 / 100;
> \$avp(i:55) = \$avp(i:70) * .006;
> \$avp(i:55) = (\$avp(i:70) * .006);
>
> Im sure I tried a few more to, but basically i want to take a AVP then
> multiply it by a number and get a result, this will be a decimal like
> 0.00234
>
> Any suggestions?
>
> Thanks
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Users mailing list
> [hidden email]
> http://lists.opensips.org/cgi-bin/mailman/listinfo/users
>

```

_______________________________________________
Users mailing list
[hidden email]
http://lists.opensips.org/cgi-bin/mailman/listinfo/users
Open this post in threaded view
|

## Re: Performing math functions in OpenSIPs

 On 04.03.2010 20:05, Brad Bendy wrote: > That makes since now, we had a float actually. At this time no way to > work with floats at all right? There's always a workaround :) >>> \$avp(i:55) = \$avp(i:70) * .006; \$avp(i:55) = \$avp(i:70) * 6; Just treat i:55 as if it was multiplied by 1000. It seems like you're trying to do some cost calculation - so just assume that i:55 is expressed as the number of 10'ths of a cent. Then format it properly when needed for output. _______________________________________________ Users mailing list [hidden email] http://lists.opensips.org/cgi-bin/mailman/listinfo/users
Open this post in threaded view
|

## Re: Performing math functions in OpenSIPs

Yeah, that's exactly what I just did. Works like a champ, little confusing on the eyes when your use to seeing 5 digit decimals, but it gets the job done!

Thanks for the suggestion.

On Thu, 2010-03-04 at 20:23 +0000, Stanisław Pitucha wrote:
```On 04.03.2010 20:05, Brad Bendy wrote:
> That makes since now, we had a float actually. At this time no way to
> work with floats at all right?

There's always a workaround :)

>>> \$avp(i:55) = \$avp(i:70) * .006;

\$avp(i:55) = \$avp(i:70) * 6;

Just treat i:55 as if it was multiplied by 1000. It seems like you're
trying to do some cost calculation - so just assume that i:55 is
expressed as the number of 10'ths of a cent.

Then format it properly when needed for output.

_______________________________________________
Users mailing list
[hidden email]
http://lists.opensips.org/cgi-bin/mailman/listinfo/users
```
 -- Brad Bendy Chief Technical Officer [hidden email] Benga Networks, LLC. 10115 E. Bell Rd, Ste. 107-451 Scottsdale, AZ 85260-2189 Toll Free:    877-44-BENGA Local:          480-970-5200 Cell:             602-550-4004 Fax:             866-852-4468

_______________________________________________
Users mailing list
[hidden email]
http://lists.opensips.org/cgi-bin/mailman/listinfo/users