SQL/Answer Detail

How to round or truncate with no trailing zeros in sql server?

Liam
Liam
2 Points
1 Posts

I have following select command (round/truncate):

--Round
SELECT ROUND(100.55555552, 2)
--Truncate
SELECT ROUND(100.55555552, 2, 1)

Both giving trailing zeros

How we can remove trailing zeros?

Total Answered: 2
Total Marked As Answer: 1
Posted On: 23-Jan-2018 04:35
Share:   fb twitter linkedin
Answers
Smith
Smith
276 Points
93 Posts
 
 
Posted On: 25-Jan-2018 02:15

Use following:

--Round
SELECT convert(DOUBLE PRECISION, ROUND(100.55555552, 2))
--Truncate
SELECT convert(DOUBLE PRECISION, ROUND(100.55555552, 2, 1))
Rahul Maurya
Rahul Maurya
Moderator
1146 Points
208 Posts
Marked as answer  
 
Posted On: 25-Jan-2018 02:17

try this

--Round
SELECT CAST(ROUND(100.55555552, 2) AS DECIMAL(8,2))
--Truncate
SELECT CAST(ROUND(100.55555552, 2, 1) AS DECIMAL(8,2))

Blog

Active User (2)

 Log In to Chat