Sort numeric prices stored as text
Type the number and its unit as a single group. · 164 words
Describe the data and desired order instead of saying 'sort these prices.' A bookstore import stores prices as text: '12.50', '9.99', '120.00', and '7.50'. The source is the store's catalog price column. Ask the AI: 'Read each string as a dollar amount, sort ascending, keep the original text, and show the parsed amount.' Numeric order is 7.50, 9.99, 12.50, 120.00. A text sort can put '120.00' before '7.50' because it compares characters, not numbers. Check that each parsed amount matches its source and the output never decreases.
Try text with symbols and separators. A sports shop's old file contains '$1,299.00', '$85.50', '$999.99', and '$1,050.25'. Request descending numeric order, two decimal places, and columns for original text, parsed amount, and rank. Correct order is $1,299.00, $1,050.25, $999.99, $85.50, with ranks 1 through 4. Tell the AI to remove '$' and commas before comparison, and to flag blank or nonnumeric entries rather than guess. The checkable result has four rows, two decimals, and no missing row.
Check your recall
What is the ascending numeric order of the bookstore prices '12.50', '9.99', '120.00', and '7.50'?
Check your answer
7.50, 9.99, 12.50, 120.00. The values must be read as numbers, not sorted as text strings.
Sources and credits
Original KeyTouch lesson. Background reading · DAIR.AI · Examples of Prompts.