Forum Discussion

dhir_vl's avatar
dhir_vl
Reel Rookie
2 years ago

Timestamp delta during conversion

I have a response from server which should look like below.

{ "startDate": 1695034800, "endDate": 1695036540 }

 

However, the response is print as below in the console. 

{"startDate":1.6950348e+09,"endDate":1.69503654e+09}

 

I convert the printed startDate to a variable as below.

timestamp& = json.startDate

 

Here, I get incorrect value 1695034752, when it should have been 1695034800. How do I get the correct value? 

 

4 Replies

  • renojim's avatar
    renojim
    Community Streaming Expert

    I think you need to figure out why the server is returning a floating point number.

    • dhir_vl's avatar
      dhir_vl
      Reel Rookie

      Server is sending long int values as below. I see this in the postman.
      { "startDate": 1695034800, "endDate": 1695036540 }

      • renojim's avatar
        renojim
        Community Streaming Expert

        It works for me:

        x="{ "+chr(34)+"startDate"+chr(34)+": 1695034800, "+chr(34)+"endDate"+chr(34)+": 1695036540 }"
        ?x
        { "startDate": 1695034800, "endDate": 1695036540 }
        ?parsejson(x)
        <Component: roAssociativeArray> =
        {
            endDate: 1695036540
            startDate: 1695034800
        }
        ?parsejson(x).enddate
         1695036540
        ?parsejson(x).startdate
         1695034800
        ?parsejson(x).enddate - parsejson(x).startdate
         1740
        json=parsejson(x)
        startdate&=json.startdate
        enddate&=json.enddate
        ?startdate&
         1695034800
        ?enddate&
         1695036540
        ?enddate&-startdate&
         1740

        The numbers are just Integers, so no need really for the LongIntegers, but it doesn't affect anything.

        I don't understand where the floating point numbers are entering the situation.  Maybe post your code.