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

convert a number to decimal Expand / Collapse
Author
Message
Posted Tuesday, January 26, 2010 11:52 AM


SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Friday, May 17, 2013 1:15 PM
Points: 114, Visits: 186
Suppose:
Declare @mynumber int
Set @mynumber = 10299


How can I return 102.99 from this or if the variable will be given at runtime, how can I process it to return a number with the first two digits being the decimal.
Post #853868
Posted Tuesday, January 26, 2010 11:58 AM


SSC-Dedicated

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

Group: General Forum Members
Last Login: Today @ 2:32 PM
Points: 32,906, Visits: 26,792
Faye Fouladi (1/26/2010)
Suppose:
Declare @mynumber int
Set @mynumber = 10299


How can I return 102.99 from this or if the variable will be given at runtime, how can I process it to return a number with the first two digits being the decimal.

The same way you'd do it manually. Divide by 100.0.


--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 #853871
Posted Tuesday, January 26, 2010 12:01 PM


SSC-Insane

SSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-Insane

Group: General Forum Members
Last Login: Today @ 11:17 PM
Points: 21,617, Visits: 27,450
Faye Fouladi (1/26/2010)
Suppose:
Declare @mynumber int
Set @mynumber = 10299


How can I return 102.99 from this or if the variable will be given at runtime, how can I process it to return a number with the first two digits being the decimal.


As Jeff said:

select @mynumber / 100.0



Lynn Pettis

For better assistance in answering your questions, click here
For tips to get better help with Performance Problems, click here
For Running Totals and its variations, click here or when working with partitioned tables
For more about Tally Tables, click here
For more about Cross Tabs and Pivots, click here and here
Managing Transaction Logs

SQL Musings from the Desert Fountain Valley SQL (My Mirror Blog)
Post #853872
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse