9 Replies Latest reply on Jun 28, 2016 11:43 AM by sfpx

    Strange evaluation

    sfpx

      My geolocation javascript sends the speed data to a filemaker script. If the speed is greater than 1.2, it does a certain action.

      On a particular Iphone which I don't have access (he's out on the field) , it seems than any fraction is evaluated as greater than 1.2

      I know that getasnumber("0,25") gives a result of 25 but ,from the logs, I know the script received data with a dot as the decimal separator.

       

      I'm really scratching my head with this one.

      I just can't replicate this on my Iphone.

      Is there an iphone configuration that would produce that erroneous evaluation ?

      I tried to set mine to the French settings ( comma as the decimal separator) but it still worked as it should.

       

      The javascript calls the script this way

      \"urlscheme://~/" & $$AppName & ".fmp12?&Script=Myscript&$latitude=\"+latitude+\"&$longitude=\"+longitude+\"&$accuracy=\"+accuracy+\"&$speed=\"+speed;

       

      The simplified script looks like

      if ($$ACCEPTDATA=1 and getasnumber($speed)>1.2) Do Action.

       

      I checked the logs on the server and the action has been triggered every time the $speed >0

      The strange thing is that me and another user don't have this strange behavior.

       

      If anyone has an idea...this is driving me insane

        • 1. Re: Strange evaluation
          schamblee

          I assume the issue is with a device that uses a comma as the decimal point.  Maybe set a variable with the amount then use the substitute command to replace the comma with a decimal point, then getasnumber.

          • 2. Re: Strange evaluation
            sfpx

            That's what I thought but I set my Iphone so the comma is the decimal separator and I don't get any erroneous evaluation.

             

            The problem is so strange and frustrating .

            If I was able to reproduce it , I guess it would be an extremely simple fix.

            • 3. Re: Strange evaluation
              schamblee

              I'm speculating that your device is set for the English language and the device that is having the issue is European.   So the comma is being evaluated differently, hence the reason you can't duplicate.   I would convert the . to a , and test on the European device.   Using the GetAsNumber on a English device is causing the , to be dropped.  On a European device it would not be dropped.   

              • 4. Re: Strange evaluation
                greatgrey

                If speed one is in metres or mph and on the other is km etc. it would give different results.

                • 5. Re: Strange evaluation
                  sfpx

                  I finally was able to get erroneous results on my iphone by setting it to Language English/Region France

                  Now that I'm able to reproduce the error I can work on a fix.

                  The getasnumber function has some really strange issues with the comma as the decimal separator (I may make another post detailing them).

                  • 6. Re: Strange evaluation
                    greatgrey

                    May be use Substitute(text; ","; ".")

                    • 7. Re: Strange evaluation
                      Magnus Fransson

                      Hi all,

                       

                      I created a custom function to improve the GetAsNumber() function.

                       

                      With best regards Magnus Fransson.

                       

                       

                      /*
                      Custom function for improved GetAsNumber()
                      Syntax: ~GetAsNumber ( text )
                      */
                      
                      Let
                      (
                          [
                              Comma = Left( 1/2 ; 1 )
                          ;
                              Improved = Substitute ( text ; [ "." ; Comma ] ; [ "," ; Comma ] )
                          ;
                              Result = GetAsNumber( Improved )
                          ]
                      ;
                          Result
                      )
                      
                      • 8. Re: Strange evaluation
                        sfpx

                        Some things I noticed with my multiple tests today

                        All done on my iphone with France as the Region

                         

                        Script Test1

                        Show Custom Dialog (Getasnumber(get(scriptparameter))

                         

                        Test1 ("0.25") = 0,25

                         

                        Script Test2

                        Show Custom Dialog (Getasnumber($speed))

                         

                        Open URL "myscheme://~/myapp.fmp12?&Script=test2&$speed=0.25"   = 25

                         

                        Script Test2

                        Show Custom Dialog (Getasnumber("\""&$speed&"\""))

                         

                        Open URL "myscheme://~/myapp.fmp12?&Script=test2&$speed=0.25"   = .25

                         

                        Funny stuff

                        • 9. Re: Strange evaluation
                          sfpx

                          Based on these observations I just added this simple line to my script and it seems to have fixed the problem

                          Set variable $speed ==>  "\"" & $speed & "\""

                          Then getasnumber($speed) will evaluate correctly

                           

                          I actually had plenty of solutions that worked but this one seems simpler .

                           

                          Not sure why it works that way but I guess it's related to the way the parameters are managed by the Open URL function