Shortest method to extract decimal part

One of my friends told me that in an interview he was asked “What is the shortest method to extract only decimal part from a decimal number?”

One method I know is to find the remainder by dividing by 1 using modulus operator

declare @number decimal(12,2)
set @number=887.45
select @number as number,@number%1 as decimal_part

The result is

number       decimal_part
----------- --------------------
887.45       0.45

Advertisements

2 thoughts on “Shortest method to extract decimal part

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s