I sorted weights like 1.5 kg and 1.25 kg and 1.5 came before 1.25; how do I fix that?

Give every weight the same number of digits after the decimal point, 1.50 instead of 1.5 and 2.00 instead of 2, then sort with numeric sorting on. The cause is that numeric sorting does not know about decimals: it sees «1.5» as two separate numbers, 1 and 5, compares 5 with 25 and puts 1.5 first.

Published · 3 min read

What is actually happening

With numeric sorting on, the tool finds every unbroken run of digits and compares it by its whole-number value. A decimal point is not a digit, so it cuts the run in two. To the comparison, «1.5 kg» is 1, a dot, then 5, and «1.25 kg» is 1, a dot, then 25. The first parts tie, 5 is smaller than 25, and 1.5 wins.

Here is the real output. The list 1.5 kg, 1.25 kg, 1.75 kg came back from numeric sorting in exactly the same order: 1.5, then 1.25, then 1.75. The tool page states this limit plainly: numeric sorting compares runs of whole digits only.

The fix: the same number of decimals everywhere

Write every value with two decimals and the parts after the point become comparable: 50, 25 and 75. Sorting 1.50 kg, 1.25 kg, 1.75 kg with numeric sorting gave the right answer: 1.25, 1.50, 1.75.

In a longer list of five weights that mixes whole numbers in, 0.5, 1.5, 1.25, 1.75 and 2, numeric sorting returned 0.5, 1.5, 1.25, 1.75, 2. Rewritten as 0.50, 1.25, 1.50, 1.75 and 2.00, it came out fully correct: 0.50, 1.25, 1.50, 1.75, 2.00. Whole numbers need their .00 too, so every line has the same shape.

What if I just turn numeric sorting off?

You may notice that the first list (1.5, 1.25, 1.75) sorts correctly with the option off: 1.25, 1.5, 1.75, because character-by-character comparison puts 2 before 5 before 7. That breaks as soon as the part before the point differs. Sorting 10 kg, 2 kg and 1.5 kg with numeric sorting off gave 1.5, 10, 2, so 10 kg landed above 2 kg. Turning the option off fixes one case and breaks another; padding the decimals with the option on fixes both.

Steps

  1. Give every weight the same number of decimals. In a spreadsheet, format the column to two decimal places before you copy it.
  2. Put the weight at the start of each line, since comparison starts at the first character.
  3. Paste the list into the Line sorter and tick «Numeric sorting».
  4. Choose ascending for lightest first or descending for heaviest first, then copy the result.

Related cases

  • Prices with fils or halalas behave exactly like weights: write 49.90 and 49.75, not 49.9 and 49.75.
  • Negative numbers are not understood: the minus is treated as a symbol, not a sign, so do not rely on the sorter for balances that go below zero.
  • Thousands separators cut the number too, so write 1500 rather than 1,500.

Common questions

Does the tool turn 1.5 into 1.50 for me?

No. The sorter never edits your lines, so the padding is a step you do before pasting.

Does it help to use the Arabic decimal separator «٫» instead of a dot?

No. Any character that is not a digit breaks the run of digits, so the fix stays the same: equal numbers of decimals.