Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 number to 2 decimal

Author  Topic 

doran_doran
Posting Yak Master

179 Posts

Posted - 2008-06-04 : 17:55:52
I have a column rate and there are so many numbers after the digit. I just want 2 numbers after the digit.

45.43454 should be 45.43
32.6673 should be 32.67

Thanks

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-06-04 : 17:57:42
Check out the ROUND function.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Database maintenance routines:
http://weblogs.sqlteam.com/tarad/archive/2004/07/02/1705.aspx
Go to Top of Page

doran_doran
Posting Yak Master

179 Posts

Posted - 2008-06-04 : 18:00:40
there isn's one line command for this. I need to use this for a stored procedure and view.
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-06-04 : 18:01:35
Did you check out the ROUND function?

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Database maintenance routines:
http://weblogs.sqlteam.com/tarad/archive/2004/07/02/1705.aspx
Go to Top of Page

sodeep
Master Smack Fu Yak Hacker

7174 Posts

Posted - 2008-06-04 : 18:04:00
I guess this is the one:
select left(round(32.6673 ,2),5)
Go to Top of Page

soorajtnpki
Posting Yak Master

231 Posts

Posted - 2008-06-05 : 00:21:21
hi
u can this too..
i made a small change the above by sodeep..
the following is a general solution provided your column is decimal.

select left(round(ur_number,2),charindex('.',ur_number,1)+2)
ie
select left(round(32.6673,2),charindex('.',32.6673,1)+2)

ok tanx
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-06-05 : 09:32:21

Instead of using left function, use

select cast(32.6672 as decimal(12,2))


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -