SQLite format number with 2 decimal places always

后端 未结 4 1181
日久生厌
日久生厌 2020-12-08 02:38

I have some tables in a SQLite database that contains FLOAT column type, now i want to retrieve the value with a Query and format the float field always with 2 decimal place

4条回答
  •  萌比男神i
    2020-12-08 03:35

    You can use printf as:

    SELECT printf("%.2f", floatField) AS field FROM table;
    

    for example:

    sqlite> SELECT printf("%.2f", floatField) AS field FROM mytable;
    3.56
    2.40
    4.78
    3.00
    sqlite>
    

提交回复
热议问题