Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase ««12

Split integer valuefrom decimal valye Expand / Collapse
Author
Message
Posted Monday, August 08, 2011 8:15 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Sunday, May 26, 2013 9:06 PM
Points: 5, Visits: 40
i know i can do the floor() on a decimal number and then store that to a variable and subtract it from the original number

example

@a = 2.75

@b = floor(2.75)

@c = @a - @b (this gives me 0.75)

but is there a function that does this in SQL Server

Cheers,
Chandra
Post #1156497
Posted Monday, August 08, 2011 8:16 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Sunday, May 26, 2013 9:06 PM
Points: 5, Visits: 40
i know i can do the floor() on a decimal number and then store that to a variable and subtract it from the original number

example

@a = 2.75

@b = floor(2.75)

@c = @a - @b (this gives me 0.75)

but is there a function that does this in SQL Server

Cheers,
Chandra
Post #1156498
Posted Monday, August 08, 2011 9:36 PM


SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: Tuesday, April 01, 2014 5:55 PM
Points: 957, Visits: 1,027
If you can't use convert(), you can always use cast(). BTW, I can't remember how floor() behaves for negative numbers, but I know there's a reason I end up using round() instead.
Post #1156507
Posted Monday, August 08, 2011 10:03 PM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: General Forum Members
Last Login: Today @ 6:46 AM
Points: 35,951, Visits: 30,236
vchandm23 (8/8/2011)
but is there a function that does this in SQL Server


Not in any version of SQL Server that I know of. You're pretty much stuck with doing the math like you did.


--Jeff Moden
"RBAR is pronounced "ree-bar" and is a "Modenism" for "Row-By-Agonizing-Row".

First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column."

"Change is inevitable. Change for the better is not." -- 04 August 2013
(play on words) "Just because you CAN do something in T-SQL, doesn't mean you SHOULDN'T." --22 Aug 2013

Helpful Links:
How to post code problems
How to post performance problems
Post #1156510
Posted Tuesday, August 09, 2011 11:31 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Thursday, April 18, 2013 5:47 AM
Points: 20, Visits: 159
vchandm23:

What about using modulus (%)? Like some flavor of the following:

select replace(1234.4321 % 1 ,'0.','')



Post #1157078
« Prev Topic | Next Topic »

Add to briefcase ««12

Permissions Expand / Collapse