Logo

SQL Server DEC2FRAC Function

Updated 2023-11-10 14:36:39.223000

Description

Use the scalar function DEC2FRAC to convert a number into its fractional representation.

Syntax

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

Arguments

@Number

the number 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

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.

column 1
355/113
select wct.DEC2FRAC(3.14159265358979, 10);

This produces the following result.

column 1
144029661/45846065
select wct.DEC2FRAC(.667, 3);

This produces the following result.

column 1
665/997
select wct.DEC2FRAC(.667, 1);

This produces the following result.

column 1
2/3
select wct.DEC2FRAC(.66666666667, 3);

This produces the following result.

column 1
2/3