SQLite FORMAT() Function
Example
Show the price with two decimals:
SELECT ProductName, FORMAT('%.2f', Price)
FROM Products;
Try it Yourself »
Definition and Usage
The FORMAT() function formats values into a text. The first argument is a format text with codes that start with %. Each code is replaced by the next argument.
PRINTF() is an older name for the same function, and also works.
Syntax
FORMAT(format, value1, value2, ...)
Parameter Values
| Parameter | Description |
|---|---|
| format | Required. The format text. Common codes: %s (text), %d (integer), %f (decimal number), %.2f (two decimals), %05d (five digits, with leading zeros), %,d (with thousands separators), %% (a % sign) |
| value1, value2, ... | Optional. The values to put into the format text |
Technical Details
| Return type: | Text |
|---|---|
| Works in: | SQLite 3.38.0 and later |
More Examples
Example
Put values into a sentence:
SELECT FORMAT('%s costs %.2f', ProductName, Price)
FROM Products;
Try it Yourself »