FRAC function

Purpose: FRAC returns the fractional portion of a floating-point number.


 Syntax:

 RetVal = FRAC(Number)

 Parameters:

  • RetVal Returned fractional portion of floating point Number. The data type of RetVal(single or double precision) must be indicated.
  • Number Floating point(single or double precision) number.

Example:


 CLS
 
 PRINT DecToFtInch$(17.14261)
 
 
 FUNCTION DecToFtInch$ (Arg!)
   DIM Frak!
   DIM Ft!
   DIM Inch!
   DIM Sixteenths!
   DIM Reduce$
   DIM Result$
 
   Frak = FRAC(Arg)
   Ft = INT(Arg)
   Inch = INT(12*Frak)
   Sixteenths = INT(16*FRAC(12*Frak))
 
   Reduce$ = TRIM$(STR$(Sixteenths)) + "/16"
 
   SELECT CASE Reduce$
   CASE "0/16"   : Reduce$ = ""
   CASE "2/16"   : Reduce$ = "1/8"
   CASE "4/16"   : Reduce$ = "1/4"
   CASE "6/16"   : Reduce$ = "3/8"
   CASE "8/16"   : Reduce$ = "1/2"
   CASE "10/16"  : Reduce$ = "5/8"
   CASE "12/16"  : Reduce$ = "3/4"
   CASE "14/16"  : Reduce$ = "7/8"
   END SELECT
 
   Result$ = STR$(Ft) + "'" + STR$(Inch) + "-" + Reduce$
   Result$ = RTRIM$(Result$,ASC("-")) + CHR$(34)
   FUNCTION = Result$
 END FUNCTION