In SQLite how to control the formatting when converting a double to text

StackOverflow https://stackoverflow.com/questions/23627280

  •  21-07-2023
  •  | 
  •  

Frage

In SQLite, you can use CAST([column] as text) to convert a result in a string, however, for double this will result in having 1 decimal. How can I control whether I want to display decimals or the number of decimals displayed.

War es hilfreich?

Lösung

Use the printf function:

> SELECT printf("%.3f", 1);
1.000
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top