Logo

PCT2FRAC

Updated 2023-11-10 15:53:21.730000

Syntax

SELECT [westclintech].[wct].[PCT2FRAC] (
  <@Number, float,>
 ,<@Digits, int,>)

Description

Use the scalar function PCT2FRAC to convert a percentage 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 percentage to be evaluated. The @Number argument can be an expression of types that are implicitly convertible to float.

Return Type

nvarchar(4000)

Remarks

PCT2FRAC always returns a fraction in simplest form.

If @Number =1, then DEC2FRAC returns a proper fraction.

0 < @Digits < 16.

Examples

select wct.PCT2FRAC(1.25, 3);

This produces the following result.

{"columns":[{"field":"column 1","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"}],"rows":[{"column 1":"1 1/4"}]}
select wct.PCT2FRAC(1.083333333, 3);

This produces the following result.

{"columns":[{"field":"column 1","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"}],"rows":[{"column 1":"1 1/12"}]}
select wct.PCT2FRAC(1.083333333, 10);

This produces the following result.

{"columns":[{"field":"column 1"}],"rows":[{"column 1":"1 20833326/2499"}]}