Numerics vs. Strings


What is a Numeric?

A Numeric, in simple terms, is really just a number. In computer terms there are two main types of Numerics: Integer Numbers and Floating-Point Numbers. Both integers and floating-point numbers can either be negative or positive (or zero).

What is an Integer Number?

Integers are whole numbers (i.e. -3, 15, 0). Integers are ususally used in cases where you will have no use for a decimal. For example, you might number the cards in a solitaire game 1 through 52. You might also keep track of the number of people who buy school jackets. You would therefore not need decimal numbers in these cases. Another use for an integer would be as a counter. A counter will either count up or count down (usually by 1). For example, if you made a game to keep track of how many lives your character had you would keep track by using an integer counter. You might start with 3 lives and subtract 1 every time the character met its doom. When you eventually reach 0 then game is over because the character has no more lives left.

What is a Floating-Point Number?

Floating-point numbers are numbers which contain a decimal point (i.e. -5.60, 0.0, 3.14159). They are usually used in circumstances involving mathematical calculations or money. Since computers tend to perform a lot of mathematical equations most numbers used in these equations are floating-point. When you are only adding, subtracting, or multiplying an integer number you may not have use for a floating-point number. However, when you start using division and other operations you may need one. For example, even though you are dividing two integers you may get a floating-point result (i.e. 4/2 is 2 but 3/2 is 1.5). Most accounting programs use floating-point numbers with two decimal places to represent dollar figures (i.e. 52.36 would represent $53.36).

What is a String?

A String is like a small piece of rope. PUNCHA! However, in computer terms it is something quite different. A string is a collection of characters. Characters are defined as letters (a to z and A to Z), number (0 to 9), spaces, and any other symbol (!, @, #, $, %, ?, /, >, etc.). Some typical strings would be a name - Kevin Waddell (notice the space can be included as part of the string) or dollar figures which include a dollar sign (i.e. $53.36). Really you can use any combination of letters, numbers, spaces, symbols for whatever purpose you want. These are all valid strings: Player1, Tansi!, X75, 7F4&2*B!, 35.4 (notice that numerics can be defined as a string, however the numbers and the decimal points are each seen as a character and therefore cannot be used in mathematical calculations).

Differentiating Between a Numeric and a String

Liberty BASIC differentiates between a number and a string by using the double quotes. Simply put numerics are not included in double quotes (ex. 234.5) whereas strings are included in double quotes (ex. "Hello World!").

Have a look the following screen shots using the PRINT statement:


In the String example above double quotes are needed.
Strings show up in a green font.


In the Numeric example above double quotes are not needed.
Numerics show up in a red font.


A Note About Leading Zeros

Leading zeros are zeros which come at the beginning of a number. When leading zeros are used in a numeric number they will not be displayed in the run window. For example if you had the following code:

PRINT 0624

All that would show up in your run window would be:

624

To get around this, you might consider placing the number in double quotes so it becomes a string instead of a numeric:

PRINT "0624"

Now the code produces the following run:

0624

This works because a string looks at everything as just a collection of characters. Therefore a 0 is just like any other letter, number, or symbol.