How to Format a Number with Two Decimal Places in SQLite

Published Sep 22, 2021

We can use printf() in order to format floats in SQLite 3.8.3 or greater.

SELECT printf("%.2f", col_name) AS col_name 
FROM table_name;

However, if we want to reference this field later in the query, we’ll have to cast it to a number in order to make any numerical comparisons.

SELECT printf("%.2f", col_name) AS short_col_name 
FROM table_name
ORDER BY cast(short_col_name AS signed);

More SQL Articles