How to determine whether the number is float or integer How to determine whether the number is float or integer sql sql

How to determine whether the number is float or integer


declare @value float = 1IF FLOOR(@value) <> CEILING(@value)BEGIN    PRINT 'this is float number'ENDELSEBEGIN    PRINT 'this is integer number'END


Martin, under certain circumstances your solution gives an incorrect result if you encounter a value of 1234.0, for example. Your code determines that 1234.0 is an integer, which is incorrect.

This is a more accurate snippet:

if cast(cast(123456.0 as integer) as varchar(255)) <> cast(123456.0 as varchar(255)) begin   print 'non integer' end else begin   print 'integer' end

Regards,

Nico


DECLARE @value FLOAT = 1.50IF CONVERT(int, @value) - @value <> 0BEGIN    PRINT 'this is float number'ENDELSEBEGIN    PRINT 'this is integer number'END