# How do I get only the numbers after the decimal?

### Question

• How do I get only the numbers after the decimal?

Example: `2.938` = ```0.938 in SQL server ```

Saturday, September 22, 2012 5:20 AM

### All replies

• Hi,

You can use floor and then subtract that number.

```declare @d decimal(10,3)
select @d  = 2.938

select @d - floor(@d)```

if also negative number

```declare @d decimal(10,3)
select @d  = -2.938

--without Sign
select abs(@d) - floor(abs(@d))

--with sign
select cast(sign(@d) * (abs(@d) - floor(abs(@d))) as decimal(10,3))```

- Chintak (My Blog)

Saturday, September 22, 2012 5:36 AM
• Hi, there are several great techniques for the exact same example posted here:

http://stackoverflow.com/questions/3418606/sql-how-do-i-get-only-the-numbers-after-the-decimal

A really nice solution is:

```SELECT (num % 1)
```

Thanks,
Sam Lester (MSFT)

My Blog

This posting is provided "AS IS" with no warranties, and confers no rights. Please remember to click "Mark as Answer" and "Vote as Helpful" on posts that help you. This can be beneficial to other community members reading the thread.

Saturday, September 22, 2012 5:38 AM
• Thank you
Saturday, September 22, 2012 6:00 AM
• How do I get 98 out of 123498?

Example--- 123456

?

Larry Nunez

Monday, November 14, 2016 7:37 PM
• declare @int int =123498
select convert(int, reverse(left(reverse(convert(varchar(20), @int)),2)))
Monday, November 14, 2016 7:41 PM
• declare @int int =123498
select convert(int, reverse(left(reverse(convert(varchar(20), @int)),2)))

That doesn´t work in VFP 9.0

@ is not recognized in VFP, thanks anyway for tryinfg.

Larry Nunez

Monday, November 14, 2016 8:02 PM
• I am sorry, I missed that part where you mentioned this was in VFP;)
Monday, November 14, 2016 8:06 PM
• Hi Larry, you posted this question in a SQL Server forum, thus getting a solution based on TSQL code. Please post the question in the VPF forum here for better support:
https://social.msdn.microsoft.com/Forums/sqlserver/en-US/home?forum=visualfoxprogeneral

Thanks,
Sam Lester (MSFT)

http://blogs.msdn.com/samlester