Numerals

Prev Next

Numerals

B4P handles all numerals as double precision floating point numbers. This means that numerals can handle both whole numbers and numbers with decimal digits behind. Two subtypes are suppported:

  • Numerals with text represenatations
  • Plain numerals

Numerals picked up from the B4P program code or read in from tables will initially carry along their original text representations, for example 0123.40. They are useful in case the leading and trailing zeros in numbers (like in postal codes and section numbers in document structures) need to be preserved. The string representation will be discarded immediately when any kind of algorithmic operations is applied, for exmaple additions (including adding 0) and even negations. In all these cases, the subtype changes from numeral to plain numeral.

  a[0] = 123.45;
  a[1] = 007;
  a[2] = 20.20;
  a[3] = num( '1.5E-3' ); // String representation will not be included here
  a[4] = 0.00;

  for all variables( a[], b[] )
  {
      c[] = str(b[]);  // Recover string representation
      d[] = b[] + 0;       // String representation gets dropped because a calculation has been made
      e[] = str(d[]);  // Convert back to string representation

      echo;
      echo("For following numeral        : ", b[], " subtype: ", subtype(b[]) );
      echo("   String representation     : ", c[], " subtype: ", subtype(c[]) );
      echo("   Converted to plain numeral: ", d[], " subtype: ", subtype(d[]) );
      echo("   Back to string again      : ", e[], " subtype: ", subtype(e[]) );
  }
For following numeral        : 123.45 subtype: numeral
   String representation     : 123.45 subtype: quoted string
   Converted to plain numeral: 123.45 subtype: plain numeral
   Back to string again      : 123.45 subtype: quoted string

For following numeral        : 007 subtype: numeral
   String representation     : 007 subtype: quoted string
   Converted to plain numeral: 7 subtype: plain numeral
   Back to string again      : 7 subtype: quoted string

For following numeral        : 20.20 subtype: numeral
   String representation     : 20.20 subtype: quoted string
   Converted to plain numeral: 20.2 subtype: plain numeral
   Back to string again      : 20.2 subtype: quoted string

For following numeral        : 0.0015 subtype: plain numeral
   String representation     : 0.0015 subtype: quoted string
   Converted to plain numeral: 0.0015 subtype: plain numeral
   Back to string again      : 0.0015 subtype: quoted string

For following numeral        : 0.00 subtype: numeral
   String representation     : 0.00 subtype: quoted string
   Converted to plain numeral: 0 subtype: plain numeral
   Back to string again      : 0 subtype: quoted string
Try it yourself: Open LAN_Features_data_types_numerals.b4p in B4P_Examples.zip. Decompress before use.