Determine if a Float or Decimal is an Integer or Not

Vishalneeraj-24503
Posted by Vishalneeraj-24503 under Sql Server category on | Points: 40 | Views : 941
The FLOOR mathematical function returns the largest integer less than or equal to the specified numeric expression.
We can check using below code:-
DECLARE @Input FLOAT
SET @Input = 123.456

IF @Input = FLOOR(@Input)
PRINT '@Input is an Integer'
ELSE
PRINT '@Input is NOT an Integer'

SET @Input = 1234.000
IF @Input = FLOOR(@Input)
PRINT '@Input is an Integer'
ELSE
PRINT '@Input is NOT an Integer'
GO

Output:-
@Input is NOT an Integer
@Input is an Integer

Comments or Responses

Login to post response