Numbers

Prev Next

Introduction

In the B4P language, numbers are numeric values which optionally contain decimal points. The same applies to reading numbers from tables. Following rules apply:

  • It must contain at least 1 digit (0..9)
  • Negative numebers start with a minus sign (see: unary operators)
  • The number must not contain spaces and/or thousand separator symbols. Use clean num() to remove such symbols automatically.
  • At most one decimal point may be used. More points inside make the value look like a plain text.
    • A lone decimal describes a plain text containing one character.
    • At least one digit must be added before or after the decimal point, e.g. 5. or .5 are OK, specifying 5 and 0.5.
  • Leading zeros in front and trailing zeros after the digits after the comma are OK
  • Scientific notation: Not supported for the reason that some coded data (e.g. special abbreviations) may look similar to scientific notation. See next section for more details..
    • However, use num() or clean num() to specify scientific notations.
    • Exceptions: Table entries may contain numbers in scientific notation, but use table configure() to activate reading scientific notation.
    • Scientific notation is also supported in numbers in JSON files. See variable load() to load JSON files.

       echo( 1 );                   // Simple numeral
       echo( 1 1 + 2 2 );           // Attention: These two numbers are strings : '1 12 2' is returned, not '33' or '3 3'
       echo( 123.45 );
       echo( 0123.450 );            // Same value as above
       echo( 0123.450 *1);          // Operation applied (multplied by 1), therefore text representation has been dropped
1
1 12 2
123.45
0123.450
123.45
Try it yourself: Open LAN_Features_Number.b4p in B4P_Examples.zip. Decompress before use.

See also

Numerals
Scientific Notation