DEC2FRAC
Updated 2023-11-10 14:36:39.223000
Syntax
SELECT [westclintech].[wct].[DEC2FRAC] (
<@Number, float,>
,<@Digits, int,>)
Description
Use the scalar function DEC2FRAC to convert a number into its fractional representation.
Arguments
@Digits
is the maximum number of digits in the denominator of the fraction. The @Digits argument can be an expression of types that are implicitly convertible to int.
@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
DEC2FRAC always returns a fraction in simplest form.
If @Number =1, then DEC2FRAC returns an improper fraction.
0 < @Digits < 16
Examples
select wct.DEC2FRAC(3.14159265358979, 3);
This produces the following result.
{"columns":[{"field":"column 1"}],"rows":[{"column 1":"355/113"}]}
select wct.DEC2FRAC(3.14159265358979, 10);
This produces the following result.
{"columns":[{"field":"column 1"}],"rows":[{"column 1":"144029661/45846065"}]}
select wct.DEC2FRAC(.667, 3);
This produces the following result.
{"columns":[{"field":"column 1"}],"rows":[{"column 1":"665/997"}]}
select wct.DEC2FRAC(.667, 1);
This produces the following result.
{"columns":[{"field":"column 1","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"}],"rows":[{"column 1":"2/3"}]}
select wct.DEC2FRAC(.66666666667, 3);
This produces the following result.
{"columns":[{"field":"column 1","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"}],"rows":[{"column 1":"2/3"}]}