views:

136

answers:

3

How to round with no trailing zeros in SQL Server 2005?

    select round(100.5555, 2)

...yields 100.55**00**. How to get rid of the zeros?

+1  A: 

declare @d decimal(8,2) can help you.

Saar
+1  A: 

Try this

select CAST(round(100.5555, 2) AS DECIMAL(8,2))
astander
What if I don't know the lenght 8, the only thing I know is that I need 2 digits arter dot?
Alex
@astander: I got it, 8 is maximum, so I can just put any large enough number. Thanks!
Alex
A: 

You could re-cast it as your original datatype, e.g.

SELECT CAST(ROUND(100.5555, 2) AS FLOAT)

However, this sounds like display logic and therefore, I suspect you are better off doing this within your UI rather than your DB.

Robin Day