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
You could try Select Str(12345.6789, 12, 3)
displays: ' 12345.679'
( 3 spaces, 5 digits 12345, a decimal point, and three decimal digits (679). - it rounds if it has to truncate, (unless the integer part is too large for the total size, in which case asterisks are displayed instead.)
for a Total of 12 characters, with 3 to the right of decimal point.
Due to the way sqlite stores numbers internally,
You probably want something like this
select case when substr(num,length(ROUND(floatField,2))-1,1) = "." then num || "0" else num end from table;
On older versions of SQLite that don't have PRINTF
available you can use ROUND
.
For example...
SELECT
ROUND(time_in_secs/1000.0/60.0, 2) || " mins" AS time,
ROUND(thing_count/100.0, 2) || " %" AS percent
FROM
blah
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>