FRAC function

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


 Syntax:

 RetVal = FRAC(Number)

 Parameters:

  • Number Floating point(single or double precision) number.

 Return Value:

  • RetVal, the return value, is the fractional portion of floating point Number. The data type of RetVal(single or double precision) must be indicated.

Example:


 CLS
  
 PRINT DecToFtInch$(17.14261)
  
  
 FUNCTION DecToFtInch$ (DecMeasure!)
   DIM Frak!
   DIM Ft%
   DIM Inch%
   DIM Sixteenths%
   DIM Reduce$
   DIM Result$
  
   Frak! = FRAC(DecMeasure!)
   Ft% = INT(DecMeasure!)
   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