views:

93

answers:

4

Assume i have 4.9 value.

I would like to split 4 and .9 ... How can i do it?

I could isolate 4 by using FLOOR(). What about the .9? How can i isolate it?

I'm using t-sql sql server 2005/2008

+10  A: 
4.9%1

You can do modulus divide 1.

thyrgle
Awesome!!!...........
Beginner_Pal
@thyrgle.. isn't 0.9 the remainder of the 4.9/1 integer division ? but the answer is great +1
Gaby
@Gaby: Yeah I guess now that I think of it, but I remember someone saying it isn't.
thyrgle
+1 for such a simple answer
Nico Burns
+1.. for a minute i dint believe it will work till I actually tried it out!
Roopesh Shenoy
A: 
Declare @dec decimal(8,2)

Set @dec = 23.98

Select Left(@dec, CharIndex('.',@dec)-1) as 'LeftPortion',
        RIGHT(@Dec, len(@dec) - CharIndex('.',@dec)) as 'RightPortion'
Barry
+2  A: 

The easiest i can think would be

SELECT IntegerPart = cast(4.9 AS int), DecimalPart = 4.9 - cast(4.9 AS int)
Gaby
A: 

Take a look at the parsename function. I think the code below will produce the desired results. select parsename(4.9,2) gives the 4 select parsename(4.9,1) gives the 9 The output of parsename can be directly used as a number such that select parsename(4.9,2)* 2 give the vaule 8

RC_Cleland