BB___Numbers

=Numbers= toc

Description
> This topic deals with numbers in general, and how to convert numbers to strings. For mathematical operations with numbers see Mathematics. > Numbers could be integers (AKA whole numbers) – without decimal point – and real numbers (AKA floating point numbers). Since Just BASIC has no Boolean (logical, yes/no true/false) datatype, numbers are used for this purpose as well. Just BASIC has only one number type ("just a number"), so all this complexity is hidden.

> If you want to understand what’s going on "under the hood", there is an article at LPBE describing how LB (and JB) stores numbers, what abilities it has, and what limitations and gotchas we can encounter: [|Numbers in Liberty BASIC].

Syntax
There is no syntax for using numbers. There are some conventions for how to represent numbers in JB. (I suppose you could call this syntax...). > This is common shortcut for, big E works as well.
 * 1) **a whole number:  **
 * 2) **an integer:  **
 * 3) **a floating point:  **
 * 4) **scientific notation:  **

Hints
> You cannot do mathematical calculations with a string representation of a number. To do the calculations, you must use the val function to convert the string back to a number. >> code format="lb" num=12345.67890 print "1", using("#####.##", num) print "2", using("#######.##", num) print "3", using("##.##", num) 'produces: '1            12345.68 '2               12345.68 '3             %12345.68
 * //**Displaying numbers.**// Generally speaking, the result of a math operation involving whole numbers will be an integer number with no decimal point and 0. Operations involving decimal numbers will produce results as floating point numbers of arbitrary length.
 * //**Rounding.**// There is no direct way to truncate or round a number in JB, say to 2 places, except you can //**display**// a number to a rounded output using the **using** function (see below). The integer function (int) does not round a number; it merely returns the whole number to the left of the decimal point.
 * //**Converting numbers.**// There is no need to define a number type, or to use a function to convert to a different type. This is all done automatically in JB. You can, however, convert a number to a string using the str$ function. This function returns the argument as a character representation of the number.
 * //**The Using Function.**// The using function (See Using), uses a template string (a mask), to represent the number of characters to display to each side of the decimal point. When doing this, the numbers to the right of the decimal point are automatically rounded and truncated to fit the template. Numbers to the left of the decimal are never truncated or rounded. If the number of digits is less than the characters in the template, leading spaces are prepended to pad the number to match the template. If the template shows fewer characters than there are digits in the number, the number is not truncated; instead, a percent sign (%) is prepended to the number display to show it does not fit the template. You should be aware of these conventions when displaying numbers in columns. Here's an example:

'instead, do this: print "1", using("#######.##", 12345.67890) print "2", using("#######.##", 123456.67890) print "3", using("#######.##", 12.67890) 'which produces: '1              12345.68 '2              123456.68 '3                  12.68 code

Example
code format="lb" Place a simple, working example of the keyword here code

Useful Procedures
code format="lb" Place a useful function using this keyword here code