Login     Register

        Contact Us     Search

XLeratorDB/strings Online Documentation

SQL Server percentage-to-fraction function


PCT2FRAC

Updated: 30 April 2009


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


 
select wct.PCT2FRAC(1.083333333, 3)
 
This produces the following result
---------------
1 1/12
 
(1 row(s) affected)
 

 
select wct.PCT2FRAC(1.083333333, 10)
 
This produces the following result
---------------
1 20833326/249999913
 

(1 row(s) affected)



Copyright 2008-2024 Westclintech LLC         Privacy Policy        Terms of Service