Logo

SQL Server PCT2FRAC Function

Updated 2023-11-10 15:53:21.730000

Description

Use the scalar function PCT2FRAC to convert a percentage into its fractional representation.

Syntax

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

Arguments

@Number

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

@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.

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.

column 1
1 1/4
select wct.PCT2FRAC(1.083333333, 3);

This produces the following result.

column 1
1 1/12
select wct.PCT2FRAC(1.083333333, 10);

This produces the following result.

column 1
1 20833326/2499