Sort for numbers less than 10

I’m sorting a list of numbers with the following action code:

^value((collect_if(descendants(this),$Prototype=="Data Extract",$PID)).unique.sort.format("<ol>","<li>","</li>","</ol>"))^

And getting the following result:

The attribute $PID type is number. I’ve tried to change that to 05 but it doesn’t take.

Ideas?

Beck,

There’s a specific sort for number attributes .nsort(). List.nsort([$Attribute])

Does that work?

2 Likes

Sure does! Didn’t know about .nsort(). Thank you, @brookter!

You’re welcome!

I was going to suggest that I think you can pad the single numbers for right alignment but it looks like there are a few wrinkles to that: Number.format(decimalsN[,widthN][,padStr])

Interesting! Thanks for the tip.

@brookteris correct on .nsort for sorting numbers (i.e. Number-type data). The number.format()approach, linked to above results in a _String_. If you were making zero-left-padded number strings, then.sort` would work.

Why this variation in the way things sort? See more on Lexical vs. Numeric sorting