small correction ... On 21.09.23 14:04, Daniel-Constantin Mierla wrote: > If you know the values is in range 0..100, then maybe something like: > > if($var(x)>10) {
^^^ if($var(x)>=10) { > $var(q) = "" + ($var(x) / 100) + "." + ($var(x) mod 100); > } else { > $var(q) = "0.0" + $var(x); > } > > The interpreter does auto-conversion to the type of the first value in > the right side. > > Cheers, > Daniel > > On 21.09.23 13:51, Barry Flanagan wrote: >> On 21/09/2023 12:49, Daniel-Constantin Mierla wrote: >>> Hello, >>> >>> if you don't need to store it as a floating point number, but to use it >>> somewhere in a string, it should be possible without sql tricks, that's >>> why I asked to see where you need it. >> Yes, that is what I need. I simply need the resulting string from "1 - >> (X/100)" to use in append)branch() >> >> -Barry >> >>> Cheers, >>> Daniel >>> >>> On 21.09.23 13:27, Barry Flanagan wrote: >>>> On 21/09/2023 08:10, Daniel-Constantin Mierla wrote: >>>>> Hello, >>>>> >>>>> where do you use the value? Do you set it to $var(...) or another >>>>> variable? Which? Or do you use it to compose a string with some >>>>> address >>>>> having q parameter? >>>> Hi Daniel, >>>> >>>> I actually found the issue. I am using an SQLite db for this, and it >>>> is a bit funny in how it handles floating point. I get the correct >>>> value when I query "SELECT 1.00 - (20.00/100.00);" >>>> >>>> Thanks >>>> >>>> -Barry >>>> >>>> >>>>> Cheers, >>>>> Daniel >>>>> >>>>> On 20.09.23 17:17, Barry Flanagan wrote: >>>>>> On Wed, 20 Sep 2023, at 14:36, Barry Flanagan wrote: >>>>>>> Hi >>>>>>> >>>>>>> I need to take in a priority (from 0 to 100, 0 being highest >>>>>>> prio) and >>>>>>> convert this into a Q value between 0 and 1.0 >>>>>>> >>>>>>> My idea was to simply do: >>>>>>> >>>>>>> q_value = 1 - ($var(priority)/100) >>>>>>> >>>>>>> However, it seems Kamailio only deals in integers in the config. A >>>>>>> Previous post suggested using xavp vars, but this ends up the same >>>>>>> result. >>>>>>> >>>>>>> Apart from doing a pseudo SQL query "SELECT 1 - (20/100)" is >>>>>>> there any >>>>>>> way within the config I can do such maths? >>>>>>> >>>>>> I tried using the SQL, and although the query returns "0.8000" the >>>>>> resulting var seems to only interpret this as an integer. How can I >>>>>> force it to be a string? I tried changing my select to "SELECT >>>>>> cast(1 - (20/100) as char(10)) AS qval" but still my result var is >>>>>> saved as 1 >>>>>> >>>>>> Thanks >>>>>> -Barry >>>>>> __________________________________________________________ >>>>>> Kamailio - Users Mailing List - Non Commercial Discussions >>>>>> To unsubscribe send an email to sr-users-le...@lists.kamailio.org >>>>>> Important: keep the mailing list in the recipients, do not reply >>>>>> only to the sender! >>>>>> Edit mailing list options or unsubscribe: >>>> -- >>>> -Barry >>>> >> -- >> -Barry >> > -- > Daniel-Constantin Mierla (@ asipto.com) > twitter.com/miconda -- linkedin.com/in/miconda > Kamailio Consultancy - Training Services -- asipto.com > Kamailio World Conference - kamailioworld.com > -- Daniel-Constantin Mierla (@ asipto.com) twitter.com/miconda -- linkedin.com/in/miconda Kamailio Consultancy - Training Services -- asipto.com Kamailio World Conference - kamailioworld.com __________________________________________________________ Kamailio - Users Mailing List - Non Commercial Discussions To unsubscribe send an email to sr-users-le...@lists.kamailio.org Important: keep the mailing list in the recipients, do not reply only to the sender! Edit mailing list options or unsubscribe: