# PRINTF

> PRINTF function in StackQL: format values into a string with a C printf-style format string.

Source: https://stackql.io/language-spec/functions/string/printf

Formats its arguments into a string according to a C `printf`-style format string.

See also:  
[[` SELECT `]](/language-spec/select) [[` CONCAT `]](/language-spec/functions/string/concat)

* * * 

## Syntax

```sql
SELECT PRINTF(format [, value ...]) FROM <multipartIdentifier>;
```

## Arguments

__*format*__  
A format string.  Conversions include `%d` (integer), `%f` (floating point, for example `%.2f`), `%s` (string), `%x` (hexadecimal), `%q` (SQL-quoted string) and `%%` (a literal percent sign), with optional flags, width and precision such as `%-30s` or `%08d`.

__*value*__  
The values substituted into the conversions, in order.

> StackQL accepts `PRINTF` only; the `FORMAT` alias that SQLite also provides is not accepted by the StackQL parser.

## Return Value(s)
Returns a string.

* * *

## Examples

### Format numbers

The following query rounds to two decimal places with a literal percent sign, pads an integer with zeros and prints a number in hexadecimal:

```sql
SELECT PRINTF('%.2f%%', 12.3456) AS pct, PRINTF('%08d', 42) AS padded, PRINTF('%x', 255) AS hex;
```

```
|-----|----------|--------|
| hex |  padded  |  pct   |
|-----|----------|--------|
| ff  | 00000042 | 12.35% |
|-----|----------|--------|
```

### Align columns in a text report

The following query pads repository names to a fixed width and right-aligns their star counts:

```sql
SELECT PRINTF('%-35s %5d stars', name, stargazers_count) AS line
FROM github.repos.repos
WHERE org = 'stackql-labs';
```

For more information, see [https://www.sqlite.org/printf.html](https://www.sqlite.org/printf.html)
