Henrik
Henrik

Reputation: 1807

Integer to decimal with 2 decimal places

I want to cast an integer to a decimal with 2 decimal places.

I've tried with:

select cast(sum as decimal(18,2)) FROM ...

But it won't work. Is there any wrong in the Query ?

Fiddle

Upvotes: 0

Views: 1911

Answers (1)

CL.
CL.

Reputation: 180080

What is wrong with this query is that SQLite uses dynamic typing; this just casts to REAL.

To round a number, use the round function:

SELECT round(sum, 2) FROM ...

A database should not be concerned with formatting data; it might be a better idea to format the number in your program.

Upvotes: 1

Related Questions