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: Friday, March 22, 2013 11:49 AM
Points: 945, Visits: 998
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: Yesterday @ 9:01 PM
Points: 33,111, Visits: 27,037
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."

For better, quicker answers on T-SQL questions, click on the following...
http://www.sqlservercentral.com/articles/Best+Practices/61537/

For better answers on performance questions, click on the following...
http://www.sqlservercentral.com/articles/SQLServerCentral/66909/
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: 19, 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