Format significant decimal places in SQL Server?

How to map numbers to significant decimal places in SQL Server?

Given that it MYFIELDhas a data type NUMERIC(38,10):

Presented result:

Select MYFIELD from MYTABLE:
1000.0000000000
1234.5600000000
2000.0000000000

Best result (halfway):

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.

+4
source share
1 answer

I would highly recommend performing client-side formatting tasks for a variety of reasons. However, starting with SQL Server 2012, you can do this:

select MyField, format(MyField, '0.##') as [MyFieldFormatted]
from dbo.MyTable;
+5
source

All Articles