Logo

FIXED

Updated 2023-11-10 14:56:16.550000

Syntax

SELECT [westclintech].[wct].[FIXED] (
  <@Number, float,>
 ,<@Decimals, int,>
 ,<@No_commas, bit,>)

Description

Use the scalar function FIXED to format a number in decimal format using a period and commas, round the number to the specified number of decimals, and return the result as text.

Arguments

@Decimals

is the number of decimal places in the result. The @Decimals argument can be an expression of types that are implicitly convertible to int.

@No_commas

a bit value determining the presence of commas in the result.

@Number

the number to be evaluated. The @Number argument can be an expression of types that are implicitly convertible to float.

Return Type

nvarchar(4000)

Remarks

Set @No_commas = 1 to return no commas.

If @Decimals < 0, then @Number is rounded to the left of the decimal.

Examples

select wct.fixed(100, 5, 0)

UNION

select wct.fixed(1000, 5, 0)

UNION

select wct.fixed(10000, 5, 0)

order by 1;

This produces the following result.

{"columns":[{"field":"column 1"}],"rows":[{"column 1":"1,000.00000"},{"column 1":"10,000.00000"},{"column 1":"100.00000"}]}
select wct.fixed(1234567890, -3, 1);

This produces the following result.

{"columns":[{"field":"column 1","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"}],"rows":[{"column 1":"1234568000"}]}