Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL set floating point precision

For a SQL int that is being converted to a float, how do I set the precision of the floating point number?

This is the selection I would like to truncate to two or 3 decimal places:

AVG(Cast(e.employee_level as Float))avg_level,

Thanks!

like image 925
CodeKingPlusPlus Avatar asked Jun 20 '12 19:06

CodeKingPlusPlus


1 Answers

In TSQL, you can specify two different sizes for float, 24 or 53. This will set the precision to 7 or 15 digits respectively.

If all you want to do is truncate to a set number of decimal places, you can use ROUND, ie:

ROUND(AVG(CAST(e.employee_level as float)), 3)
like image 195
Bort Avatar answered Sep 20 '22 04:09

Bort