Reputation: 40388
How can I display numbers to significant decimal places in SQL Server?
Given that MYFIELD
is of data type NUMERIC(38,10)
:
Present result:
Select MYFIELD from MYTABLE:
1000.0000000000
1234.5600000000
2000.0000000000
Better result (half way there):
Select cast(MYFIELD as NUMERIC(38,2)) from MYTABLE:
1000.00
1234.56
2000.00
Desired result:
Select ??? from MYTABLE:
1000
1234.56
2000
Thanks in advance.
Upvotes: 4
Views: 619
Reputation: 7692
I would strongly suggest to perform formatting-related tasks on the client side, for a multitude of reasons. However, starting from SQL Server 2012, you can do this:
select MyField, format(MyField, '0.##') as [MyFieldFormatted]
from dbo.MyTable;
Upvotes: 5