Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Numbers are treated as strings - why?
Forum Updated to NodeBB v4.3 + New Features

Numbers are treated as strings - why?

Scheduled Pinned Locked Moved Solved QML and Qt Quick
3 Posts 2 Posters 223 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    PawlosCK
    wrote on last edited by
    #1

    Why numbers are treated as strings? Please look at variable " alarm.stop_date_unix_timestamp"

        function runAlarm(timer_value_sec, type_value, message_value)
            {
                alarm.start_date_unix_timestamp = Math.round((new Date()).getTime() / 1000)
                alarm.stop_date_unix_timestamp = alarm.start_date_unix_timestamp + timer_value_sec
                alarm.type_of_alarm = type_value
                alarm.message = message_value
        
                console.log("runAlarm =============================================")
        //        console.log("type_value: " + type_value)
        //        console.log("message_value: " + message_value)
                console.log("timer_value_sec: " + timer_value_sec)
                console.log("alarm.start_date_unix_timestamp: " + alarm.start_date_unix_timestamp)
                console.log("alarm.stop_date_unix_timestamp: " + alarm.stop_date_unix_timestamp)
                console.log("=============================================")
        
                timerAlarmID.start()
            }
    
    qml: runAlarm =============================================
    qml: timer_value_sec: 5
    qml: alarm.start_date_unix_timestamp: 1605393976
    qml: alarm.stop_date_unix_timestamp: 16053939765
    qml: =============================================
    
    JKSHJ 1 Reply Last reply
    0
    • P PawlosCK

      Why numbers are treated as strings? Please look at variable " alarm.stop_date_unix_timestamp"

          function runAlarm(timer_value_sec, type_value, message_value)
              {
                  alarm.start_date_unix_timestamp = Math.round((new Date()).getTime() / 1000)
                  alarm.stop_date_unix_timestamp = alarm.start_date_unix_timestamp + timer_value_sec
                  alarm.type_of_alarm = type_value
                  alarm.message = message_value
          
                  console.log("runAlarm =============================================")
          //        console.log("type_value: " + type_value)
          //        console.log("message_value: " + message_value)
                  console.log("timer_value_sec: " + timer_value_sec)
                  console.log("alarm.start_date_unix_timestamp: " + alarm.start_date_unix_timestamp)
                  console.log("alarm.stop_date_unix_timestamp: " + alarm.stop_date_unix_timestamp)
                  console.log("=============================================")
          
                  timerAlarmID.start()
              }
      
      qml: runAlarm =============================================
      qml: timer_value_sec: 5
      qml: alarm.start_date_unix_timestamp: 1605393976
      qml: alarm.stop_date_unix_timestamp: 16053939765
      qml: =============================================
      
      JKSHJ Offline
      JKSHJ Offline
      JKSH
      Moderators
      wrote on last edited by
      #2

      @PawlosCK said in Numbers are treated as strings - why?:

      Why numbers are treated as strings?

      Possibly because the called passed a string instead of a number?

      Check with

      console.log(typeof timer_value_sec)
      console.log(typeof alarm.start_date_unix_timestamp)
      console.log(typeof alarm.stop_date_unix_timestamp)
      

      Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

      1 Reply Last reply
      1
      • P Offline
        P Offline
        PawlosCK
        wrote on last edited by
        #3

        Thanks. Problem solved. In code I had line

        var number = ""
        

        and I put this variable as parameter into function.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved