Get only decimal in floating point in SQL Server

I have the following number in SQL Server 2008: 5.4564556
I just want to get only 4564556 from 5.4564556
it would be better if I could only get 4 out of 4564556, which is the first digit of the fractional part.

How can i do this?

thanks

+4
source share
5 answers

you can get the first four decimal parts:

select SUBSTRING (PARSENAME(5.4564556,1), 1, 4) 
+2
source

You can try this way:

 SELECT (5.4564556 % 1) 
+8
source

You can also use FLOOR () :

 SELECT Value - FLOOR(Value) 

In your case:

5.4564556 - 5 = 0.4564556

in case of a negative value, you can use ABS

 SELECT ABS(Value) - ABS(FLOOR(Value)) 
+7
source

To get all numbers for ".", You can (ab) use PARSENAME

 select PARSENAME(5.4564556,1) 

returns 4564556

See also SQL - How to get only numbers after decimal number?

+5
source

try it

  select cast(5.4564556 % 1 * 10 as int) 
+2
source

All Articles