EasyManua.ls Logo

Commodore 128 - Basic Functions; The INTEGER Function (INT); What Is a Function

Commodore 128
448 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
BASIC FUNCTIONS
What is a Function
A function is a predefined operation of the BASIC language that
generally provides you with a single value. When the function
provides the value, it is said to "return the value. For instance,
the SQR (square) function is a mathematical function that returns
the value of a specific number when it is raised to the second
poweri.e., squared.
There are two kinds of functions:
Numericreturns a result which is a single number.
Numeric functions range from calculating mathematical
values to specifying the numeric value of a memory location.
Stringreturns a result which is a character.
Following are descriptions of some of the more commonly used
functions. For a complete list of BASIC 7.0 functions see Chapter
V, BASIC 7.0 Encyclopaedia.
The INTEGER Function (INT)
What if you want to round off a number to the nearest integer?
Youll need to use INT, the integer function. The INT function
takes away everything after the decimal point. Try typing these
examples:
? in t (4.25) a r r a s #
? INT(4.75) ftETtSBf
? INT(SQR(50)) RETURN
If you want to round off to the nearest whole number, then the
second example should return a value of 5. ln fact, you should
round up any number with a decimal above 0.5. To do this, you
have to add 0.5 to the number before using the INT function, ln
this way, numbers with decimal portions above 0.5 will be
increased by 1 before being rounded down by the INT function.
Try this:
? INT(4.75+0.5) n rn m ir
The computer added 0.5 to 4.75 before it executed the INT
function, so that it rounded 5.25 down to 5 for the result. If you
want to round off the result of a calculation, do this:
4-20

Table of Contents

Other manuals for Commodore 128

Related product manuals