Home > Enterprise >  Return number of rows as decimal
Return number of rows as decimal

Time:06-02

Is there a way to make COUNT return a decimal?

For example:

SELECT 3 / 5 * 100 returns a value of 0

SELECT 3.0 / 5.0 * 100 returns a value of 60

If the COUNT results are 3 and 5, how can I make the results to store as 3.0 and 5.0?

CodePudding user response:

To return a Decimal You can:

float(3.0 / 5.0 * 100)

If you want any variable to be float example a = 9 print(float(a) The result will be 9.0

Hope it help!

CodePudding user response:

SELECT CAST(COUNT(*) AS DECIMAL(15,3)) AS DecimalCount
FROM MyTable
  • Related