Login     Register

        Contact Us     Search

XLeratorDB/strings Online Documentation

SQL Server decimal-to-fraction function


DEC2FRAC

Updated: 30 April 2009

Use DEC2FRAC to convert a number into its fractional representation.
Syntax
SELECT [wctString].[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 Types
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
------------------------------------------------------------------------------
355/113
 
(1 row(s) affected)
 


select
wct.DEC2FRAC(3.14159265358979, 10)
 

This produces the following result
------------------------------------------------------------------------------
144029661/45846065
 
(1 row(s) affected)
 
 

select
wct.DEC2FRAC(.667, 3)
 

This produces the following result
------------------------------------------------------------------------------
665/997
 
(1 row(s) affected)
 


select
wct.DEC2FRAC(.667, 1)
 

This produces the following result
-------------------------------------------------------------------------------
2/3
 
(1 row(s) affected)
 


select
wct.DEC2FRAC(.66666666667, 3)

This produces the following result
------------------------------------------------------------------------------
2/3
 
(1 row(s) affected)


Copyright 2008-2013 WestClinTech LLC         Privacy Policy        Terms of Service