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
Participant
332 Points
101 Posts
     

Use following:

--Round
SELECT convert(DOUBLE PRECISION, ROUND(100.55555552, 2))
--Truncate
SELECT convert(DOUBLE PRECISION, ROUND(100.55555552, 2, 1))
Posted On: 25-Jan-2018 02:15
Rahul Maurya
Rahul M...
Moderator
1152 Points
211 Posts
Marked as answer      

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))
Posted On: 25-Jan-2018 02:17

Blog

Active User (2)

 Log In to Chat