logo
  • Home
  • Contact
💵
Should I be buying I-Bonds in 2023?
💰
Need a step-by-step guide to opening your Roth IRA?
Buy me a coffee Buy me a coffee
aws c++ career cli css docker finance git java js misc python sql

How to Format a Number with Two Decimal Places in SQLite


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);

Related in SQL

How to Group By Alias in an AWS Athena SQL Query
How to Group Rows Into Buckets with Count in a SQL Query
How to Get the Average String Length of a Column in MySQL
How to Check If Value Exists in a MySQL Table
How to Query a Table Using MySQL CLI
How to Get All Keys in JSON Object from MySQL
How to Query JSON Objects in MySQL
How to Match Columns that Contain a Substring in SQL
How to Set Up a Free PostgreSQL Database on Heroku
How to Change the Primary Key to Another Column in SQL Server
How to Modify Table to Use Composite Primary Key in MySQL
How to Order By Multiple Columns in SQL
How to Count the Number of Rows with the Same Value
How to Order a SQL String Column By Its Numeric Value
How to Check if a Column is Null in MySQL
© , LogFetch   âˆ™   Advertise Here   âˆ™   Privacy Policy