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

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

  •  21-07-2023
  •  | 
  •  

Question

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.

Était-ce utile?

La solution

Use the printf function:

> SELECT printf("%.3f", 1);
1.000
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top