Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQLite format number with 2 decimal places always

Tags:

sql

sqlite

People also ask

How do you keep 2 decimal places?

Rounding a decimal number to two decimal places is the same as rounding it to the hundredths place, which is the second place to the right of the decimal point. For example, 2.83620364 can be round to two decimal places as 2.84, and 0.7035 can be round to two decimal places as 0.70.

How do you keep a float up to 2 decimal places?

format("%. 2f", 1.23456); This will format the floating point number 1.23456 up-to 2 decimal places, because we have used two after decimal point in formatting instruction %.

Does SQLite support decimal?

2.2.The decimal extension is not (currently) part of the SQLite amalgamation.


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>