Categories
Latest
Popular

MS SQL Server Division not returning Fractional Values

 

MSSQL Server Numeric Division always raise confusions

eg. suppose we are executing

select 100 / 3

Result=33

not 33.333333

this is because division of int with another  int will be of data type int again

this is called implicit type casting , to acheive accurate results with fractional part change the above query with the following one

select cast (100 as float) / cast (3 as float)

Now Result will be 33.333333

the same thing can be do like this

select 100.00 / 3

Now Result will be again  33.333333

Here 100.00 will be treated as float with out explicitly type casting in to float, and there by float / int = float