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. Strange behavior of .arg()
Forum Updated to NodeBB v4.3 + New Features

Strange behavior of .arg()

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
3 Posts 2 Posters 190 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.
  • L Offline
    L Offline
    lolopolosko
    wrote on last edited by
    #1

    Hello,

    I try to format string "%1/%2/%3" with numbers and found that arg() method can't properly format that string if we parse number from string and put it in an arg() function

    For example:

    var string_number = "1234567"
    var formatted_string = "%1/%2/%3".arg(parseInt(string_number)).arg(12345).arg(1234)
    
    Result:
    formatted_string = 1.23457e+06/12345/1234
    
    Expected:
    formatted_string = 123457/12345/1234
    
    console.log(parseInt(string_number)) -> 1234567
    

    As I remember in older Qt version (5.6) this works as it expected, but now I try to use this code in 5.12+ and all strings that contains more than 6 characters (numbers) converted into double by arg() function

    Can anyone explain me why Qt arg() works like that? And is there any way to make it work without using toFixed(0) for example?

    sierdzioS 1 Reply Last reply
    0
    • L lolopolosko

      Hello,

      I try to format string "%1/%2/%3" with numbers and found that arg() method can't properly format that string if we parse number from string and put it in an arg() function

      For example:

      var string_number = "1234567"
      var formatted_string = "%1/%2/%3".arg(parseInt(string_number)).arg(12345).arg(1234)
      
      Result:
      formatted_string = 1.23457e+06/12345/1234
      
      Expected:
      formatted_string = 123457/12345/1234
      
      console.log(parseInt(string_number)) -> 1234567
      

      As I remember in older Qt version (5.6) this works as it expected, but now I try to use this code in 5.12+ and all strings that contains more than 6 characters (numbers) converted into double by arg() function

      Can anyone explain me why Qt arg() works like that? And is there any way to make it work without using toFixed(0) for example?

      sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      @lolopolosko perhaps a bit wrong question, but why do you need to parse the integer at all? arg() can print strings, too.

      (Z(:^

      L 1 Reply Last reply
      0
      • sierdzioS sierdzio

        @lolopolosko perhaps a bit wrong question, but why do you need to parse the integer at all? arg() can print strings, too.

        L Offline
        L Offline
        lolopolosko
        wrote on last edited by
        #3

        @sierdzio yeah, I know.. but before format string I need to do some calculation with my number and after that put it to string

        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