I have a number greater than 10 digit and that stored as a text Is there any way to sort them?

Certified Senior Developer

I have number greater than 10 digit and that stored as a text and  I want sort them. I have tried with sortextarray() that is sorting based on ascii values so it is not giving me correct output. and I tried to convert into int but that is giving me infinity Please help me here to sort the array.

Thanks in advance.

  Discussion posts and replies are publicly visible

Parents
  • Hi - it'll seem like a long way around but as along as you can guarantee all of your values only contain numerics (i.e. 0 thru 9) then you can:

    • cast each Text item to Decimal
    • generate a Dictionary form this list
    • sort the data
    • cast each Decimal back to Text

    If there's any danger that an individual item might not contain all numerics you can test for this whilst looking to cast an individual item and return, say, null to your output array, and then reject all of the null values in your output array.

  • Definitely like Stewart's approach the most.

    a!localVariables(
      local!data: {"3504051867","350405187","350405188","350405189","3604051899","360405189"},
      index(
        index(
          todatasubset(
            a!forEach(
              items: local!data,
              expression: a!map(
                decimalNumber: todecimal(fv!item),
                textNumber: fv!item
              )
            ),
            a!pagingInfo(
              startIndex: 1,
              batchSize: -1,
              sort: a!sortInfo(
                field: "decimalNumber",
                ascending: false
              )
            )
          ),
          "data",
          {}
        ),
        "textNumber",
        {}
      )
    )

Reply Children