JSONToonPro
Number utility tool

Number Sorter

Paste any list of numbers, separated by commas, spaces, or newlines, and sort them ascending or descending in one click. Supports integers, decimals, and negative numbers. Optional duplicate removal included.

100% client sideInstant resultNo data sent

Order

Separator

Input numbers
Sorted (0 numbers)
Sorted result appears here...

Why Sorting Numbers as Text Gives the Wrong Answer

This is the single most important thing to understand about sorting numbers. Text is compared character by character from the left, so "10" comes before "9" for the same reason "apple" comes before "banana": the first character 1 sorts before the first character 9, and the comparison stops right there without ever looking at the rest of the string.

[1, 5, 10, 2].sort()              -> [1, 10, 2, 5]  wrong
[1, 5, 10, 2].sort((a, b) => a - b) -> [1, 2, 5, 10]  correct

JavaScript is the classic trap here. Array.prototype.sort called with no arguments converts every element to a string before comparing, even in an array of numbers. The fix is to pass a numeric comparator: (a, b) => a - b for ascending, or (a, b) => b - a for descending. The comparator should return a negative number when a comes first, a positive number when b comes first, and zero when the two are equivalent.

The same problem appears far beyond JavaScript. Spreadsheet columns imported as text, database columns declared as VARCHAR instead of INTEGER, and CSV files parsed without type coercion all sort this way. If a sorted list looks like 1, 10, 100, 11, 2, the values are being treated as text somewhere upstream.

Ascending and Descending Order

Ascending order runs from smallest to largest, which is the default nearly everywhere and the right choice for readings you want to scan for a minimum. Descending order runs from largest to smallest and suits rankings, top-N lists, and anything where the interesting values sit at the high end. Negative numbers follow the same rule that they follow on a number line, so -50 is smaller than -3, a detail that string sorting also gets wrong.

The Statistics This Tool Reports

Alongside the sorted output the tool summarises the set. Each figure answers a different question about your data.

StatisticMeaningWhat it tells you
CountHow many values were parsedA quick check that nothing was dropped by bad separators
SumAll values added togetherTotals for quantities, amounts, and durations
MinimumThe smallest valueThe first item once sorted ascending
MaximumThe largest valueThe last item once sorted ascending
MeanThe sum divided by the countThe arithmetic average, the centre of mass of the set

One caution about the mean: it is highly sensitive to outliers. A single extreme value drags it a long way, which is why the mean salary in a small company tells you very little if one person earns ten times everyone else. The median, the middle value once the list is sorted, is robust to that: changing the largest number to something ten times larger does not move it at all. Sorting your data is the first step to reading the median off it, and comparing mean against median is a fast way to spot skew. When the mean sits well above the median, a few large values are pulling it up.

Natural Sort Order for Mixed Text and Numbers

Lexicographic order also produces surprises for strings that contain embedded numbers, which is why a file listing so often looks wrong. Natural sort order fixes this by splitting each string into runs of letters and runs of digits, then comparing the digit runs numerically rather than character by character.

lexicographic: file1, file10, file2, file20, file3
natural:       file1, file2, file3, file10, file20

Modern JavaScript can do this with Intl.Collator using the numeric option, and most operating system file managers apply natural ordering by default. If you control the data, an even simpler fix is zero padding the numbers when they are generated, since file001 through file020 sort correctly under plain text comparison.

Sort Stability

A sort is stable when items that compare as equal keep their original relative order. This is invisible when sorting plain numbers, and essential when sorting records by several keys in turn. To order employees by department and then by name within each department, you sort by name first and then by department: a stable sort preserves the name ordering inside each department group, while an unstable one scrambles it. JavaScript engines have guaranteed a stable sort since ES2019.

Practical Uses

  • Cleaning exported data: pasting a messy column out of a spreadsheet or report and getting a clean ordered list back.
  • Preparing sets for analysis: ordering measurements before reading off the median, quartiles, or range.
  • Deduplicating id lists: duplicates become adjacent once sorted, which makes them trivial to spot by eye or remove in one pass.
  • Reading log data: sorting response times or error codes surfaces the extremes immediately and shows where the range actually sits.
  • Finding gaps in sequences: a sorted list of invoice or ticket numbers makes a missing entry obvious.

Sorting is usually one step in a data cleanup pipeline. Browse the full data and developer tools collection for formatters, converters, and text utilities that handle the rest.

Frequently asked questions

5 answers
The sorter accepts commas, spaces, tabs, and newlines as separators. You can mix separators freely, for example, '1, 2 3\n4' will parse as four separate numbers. This makes it easy to paste lists from spreadsheets, code output, or plain text files.

More JSON Tools

About Number Sorting

Sorting a list of numbers is a frequent task in data analysis, spreadsheet cleanup, and programming. This tool handles the common case where you have a raw list, from a CSV export, log file, or code output, and need it ordered quickly without opening a spreadsheet or writing a script. It parses any reasonable delimiter, performs a proper numeric sort (not lexicographic), and lets you copy the sorted result to paste wherever you need it.