Click or drag to resize

Frac Function

Return the fractional portion of a number.

Namespace:  XSharp.RT
Assembly:  XSharp.RT (in XSharp.RT.dll) Version: 2.08
Syntax
 FUNCTION Frac(
	fValue AS FLOAT
) AS FLOAT
View Source

Parameters

fValue
Type: Float
The number whose fractional portion you want to return.

Return Value

Type: Float
Remarks
A number may contain a fractional portion following its integer portion.  This function returns only the fractional portion.
Examples
This example uses Frac() to implement the logic of a vending machine or a change machine:
X#
FUNCTION GiveChange(fMoney AS FLOAT) AS VOID PASCAL
LOCAL fChange AS FLOAT
? "Dollars: $", Integer(fMoney)
fChange := Frac(fMoney)
// While there is a cent left
DO WHILE fChange >= 0.01
        // Must check low amounts first:
        DO CASE
        CASE fChange < 0.05
                ? "Pay a cent"
                fChange -= 0.01
        CASE fChange < 0.10
                ? "Pay a nickel (5 cents)"
                fChange -= 0.05
        CASE fChange < 0.25
                ? "Pay a dime (10 cents)"
                fChange -= 0.10
        CASE fChange < 0.5
                ? "Pay a quarter (25 cents)"
                fChange -= 0.25
        OTHERWISE
                ? "Pay half a dollar"
                fChange -= 0.50
        ENDCASE
ENDDO
See Also