Starting from SQL Server 2012, you can format numeric types using the T-SQL FORMAT()
function. This function accepts three arguments; the number, the format, and an optional “culture” argument.
It returns a formatted string of type nvarchar.
The format is supplied as a format string. A format string defines how the output should be formatted.
Here’s an example:
SELECT FORMAT(1, 'N');
Result:
1.00
In this case, I used N
as the second argument. This is the standard numeric format specifier for Number. This particular format specifier (N
) results in the output being formatted with integral and decimal digits, group separators, and a decimal separator with optional negative sign. This argument is case-insensitive, so either N
or n
is fine.