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

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

  •  21-07-2023
  •  | 
  •  

문제

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.

도움이 되었습니까?

해결책

Use the printf function:

> SELECT printf("%.3f", 1);
1.000
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top