# FT_ROUND

```FT_ROUND()
Rounds a number to a specific place

Syntax

FT_ROUND( <nNumber> [, <nRoundToAmount>           ;
[, <cRoundType>  [, <cRoundDirection>   ;
[, <nAcceptableError> ] ] ] ] )            -> nNumber

Arguments

<nNumber> is the number to round

<nRoundToAmount> is the fraction to round to or the number of places,
default is 2.

<cRoundType> is the type of rounding desired

"D" for Decimal       (3 for thousandth, 1/1000)  (default)
"F" for Fraction      (3 for thirds, 1/3)
"W" for Whole numbers (3 for thousand, 1000)

<cRoundDirection> is the direction to round the number toward

"U" to round Up      1.31 ->  1.4
-1.31 -> -1.4
"D" to round Down    1.36 ->  1.3
-1.36 -> -1.3
"N" to round Normal  1.5  ->  2
-1.5  -> -2
1.49 ->  1
-1.49 -> -1

<nAcceptableError> is the amount that is considered acceptable
to be within, i.e., if you're within this amount of the number
you don't need to round

Returns

The number, rounded as specified.

Description

This function will allow you to round a number.  The following can
be specified:
a. Direction (up, down or normal - normal is 4/5 convention)
b. Type (whole, decimal, fraction)
c. Amount (100's, 5 decimals, 16th, etc.)

Examples

// round normal to 2 decimal places
nDollars := FT_ROUND(nDollars)

// round normal to 6 decimal places
nIntRate := FT_ROUND(nIntRate, 6)

// round to nearest thousands
nPrice   := FT_ROUND(nPrice, 3, NEAREST_WHOLE_NUMBER)

// round Up to nearest third
nAmount  := FT_ROUND(nAmount, 3, NEAREST_FRACTION, ROUND_UP)

// round down to 3 decimals Within .005
nAvg     := FT_ROUND(nAvg, 3, , ROUND_DOWN, .005)

Source: ROUND.PRG

Author: David Husnian```

# FT_RAND1

```FT_RAND1()
Generate a random number

Syntax

FT_RAND1( <nMax> ) -> nRand

Arguments

<nMax>  Maximum limit of value to be produced.

Returns

nRand is a random number between 0 (inclusive) and <nMax> (exclusive).

Description

Generates a non-integer random number based on the Linear
Congruential Method.

If you need a random number between 1 and <nMax> inclusive, INT()

If you need a random number between 0 and <nMax> inclusive,
then you should ROUND() the result.

Examples

nResult := INT( FT_RAND1(100) ) + 1    // 1 <= nResult <= 100
nResult := ROUND( FT_RAND1(100), 0 )   // 0 <= nResult <= 100
nResult := FT_RAND1( 1 )               // 0 <= nResult < 1

Source: RAND1.PRG

Author: Gary Baren```

# FT_NETPV

```FT_NETPV()
Calculate net present value

Syntax

FT_NETPV( <nInitialInvestment>, <nInterestRate>, <aCashFlow> ;
[, <nNoOfCashFlows> ] ) -> nNetPV

Arguments

<nInitialInvestment> is the amount of cash invested for purposes
of generating the cash flows.

<nInterestRate> is the annual interest rate used to discount
expected cash flows (10.5% = 10.5, not .105).

<aCashFlow> is an array of the expected cash receipts each year.

<nNoOfCashFlows> is the number of years cash flows are expected
(optional, Len( aCashFlow ) ).

Returns

The difference between the initial investment and the discounted
cash flow in dollars.

Description

This function calculates the net present value, the difference
between the cost of an initial investment and the present value
of the expected cash flow(s) from the investment.  The present
value of the expected cashflow(s) is calculated at the specified
interest rate, which is often referred to as the "cost of capital".

This function can be used to evaluate alternative investments.
The larger the NPV, the more profitable the investment.  See
also the FutureValue and PresentValue for further explanations.
The formula to calculate the net present value is:

NetPresentValue = SUM(CashFlow[i] / ((1 + InterestRate) ** i))
FOR i = 1 TO NoOfCashFlows

Examples

nNetPresentValue := FT_NETPV(10000, 10, { 10000,15000,16000,17000 } )

Source: NETPV.PRG

Author: David Husnian```

# FT_GCD

```FT_GCD()
Calculate greatest common divisor of two numbers

Syntax

FT_GCD( <nNumber1>, <nNumber2> ) -> nGCD

Arguments

<nNumber1> is the first number to find the GCD of.

<nNumber2> is the second number to find the GCD of.

Returns

The greatest common divisor of the 2 numbers, or 0 if either is 0.

Description

This function calculates the greatest common divisor between 2 numbers,
i.e., the largest number that will divide into both numbers evenly.  It
will return zero (0) if either number is zero.

Examples

? FT_GCD(10,15)                  // Result: 5
? FT_GCD(108,54)                 // Result: 54
? FT_GCD(102,54)                 // Result: 6
? FT_GCD(111,17)                 // Result: 1

Source: GCD.PRG

Author: David Husnian```