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
 General SQL Server Forums
 New to SQL Server Programming
 convert

Author  Topic 

jcb267
Constraint Violating Yak Guru

291 Posts

Posted - 2011-04-19 : 11:05:00
Hi - I have a number in my database stored as an INT that looks like 14755.25676200. However I want it to look like 14,755.26 but cannot get the convert function to work. Can anyone help me?

lionofdezert
Aged Yak Warrior

885 Posts

Posted - 2011-04-19 : 11:11:20
INT cann't containt value like 14755.25676200

Possibly u need this
DECLARE @TEST FLOAT
SET @TEST =14755.25676200
SELECT CONVERT(VARCHAR,CONVERT(MONEY, @TEST),1)
Go to Top of Page

jcb267
Constraint Violating Yak Guru

291 Posts

Posted - 2011-04-19 : 11:15:03
sorry about that, it is a decimal......
quote:
Originally posted by lionofdezert

INT cann't containt value like 14755.25676200
still
DECLARE @TEST FLOAT
SET @TEST =14755.25676200
SELECT ROUND(@TEST,2)

--------------------------
http://connectsql.blogspot.com/

Go to Top of Page

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2011-04-19 : 11:31:22
Formatting should be done in the front end. However, do you want to round or truncate?
DECLARE @N NUMERIC(13,8) = 14755.25676200

SELECT
CAST(ROUND(@N, 2, 0) AS NUMERIC(13, 2)),
CAST(ROUND(@N, 2, 1) AS NUMERIC(13, 2)),
CONVERT(VARCHAR(13), CAST(ROUND(@N, 2, 0) AS MONEY), 1),
CONVERT(VARCHAR(13), CAST(ROUND(@N, 2, 1) AS MONEY), 1)
Go to Top of Page
   

- Advertisement -