Example 2.938 = 938
Thanks
one way, works also for negative values
declare @1 decimal(4,3)
select @1 = 2.938
select PARSENAME(@1,1)
You can use FLOOR
:
select x, ABS(x) - FLOOR(ABS(x))
from (
select 2.938 as x
) a
Output:
x
-------- ----------
2.938 0.938
Or you can use SUBSTRING
:
select x, SUBSTRING(cast(x as varchar(max)), charindex(cast(x as varchar(max)), '.') + 3, len(cast(x as varchar(max))))
from (
select 2.938 as x
) a
The usual hack (which varies a bit in syntax) is
x - floor(x)
That's the fractional part. To make into an integer, scale it.
(x - floor(x)) * 1000
If you know that you want the values to the thousandths, place, it's
SELECT (num - FLOOR(num)) * 1000 FROM table...;