Click or drag to resize

Frac Function

X#
Return the fractional portion of a number.

Namespace:  XSharp.RT
Assembly:  XSharp.RT (in XSharp.RT.dll) Version: 2.21
Syntax
 FUNCTION Frac(
	fValue AS FLOAT
) AS FLOAT
Request Example 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#
 1FUNCTION GiveChange(fMoney AS FLOAT) AS VOID PASCAL
 2LOCAL fChange AS FLOAT
 3? "Dollars: $", Integer(fMoney)
 4fChange := Frac(fMoney)
 5// While there is a cent left
 6DO WHILE fChange >= 0.01
 7    // Must check low amounts first:
 8    DO CASE
 9    CASE fChange < 0.05
10        ? "Pay a cent"
11        fChange -= 0.01
12    CASE fChange < 0.10
13        ? "Pay a nickel (5 cents)"
14        fChange -= 0.05
15    CASE fChange < 0.25
16        ? "Pay a dime (10 cents)"
17        fChange -= 0.10
18    CASE fChange < 0.5
19        ? "Pay a quarter (25 cents)"
20        fChange -= 0.25
21    OTHERWISE
22        ? "Pay half a dollar"
23        fChange -= 0.50
24    ENDCASE
25ENDDO
See Also