In SQL Server, direct separation of two integers returns an integer, even if the result should be a float. The following is an example:
--1-- declare @weird_number_float float set @weird_number_float=22/7 select @weird_number_float --2-- declare @weird_number_decimal decimal(18,10) set @weird_number_decimal=22/7 select @weird_number_decimal --3-- declare @weird_number_numeric numeric set @weird_number_numeric=22/7 select @weird_number_numeric --Right way declare @weird_number float set @weird_number=cast(22 as float)/cast(7 as float) select @weird_number
Only the last block will return 3.14285714285714. Despite the fact that the second block is set with the correct accuracy, the result will be equal to 3.00000.
Suat Atan PhD Dec 19 '16 at 7:43 2016-12-19 07:43
source share