manual:chapter3:numformatting

This is an old revision of the document!


A number can be displayed on the screen in different ways, regardless of the internal precision or representation of the number. The following are examples of the possible appearance of numbers in newRPL:

123456789.123456789 (this is the default presentation)
123,456,789.123 456 789 (using thousand separators and also grouping the fractional digits)
1.23456789123456789E8 (scientific notation)

Up to 3 different ways to present numbers are used by the system, and they are active at all times. One format is for small numbers (whose absolute magnitude does not exceed a certain limit), another format for large numbers (whose absolute magnitude exceed a certain limit), and a third format for all other numbers in between. The default configuration presents numbers less than 1E-12 in scientific notation, numbers larger than 1E12 in scientific notation, and all others in standard notation. The cutoff limits for small and large numbers can be freely configured, as well as the formatting for each of the three ranges of numbers.

The primary way to change the number formatting is the SETNFMT command. This command accepts a single string or real number, or a list as arguments. Passing a single string changes all 3 formats to the desired format given by the string (the particular format of the string will be explained in short). The list allows fine grain control of what format to change as follows:
1E100 SETNFMT or 1E-10 SETNFMT: Passing a single positive real number will change the cutoff limits without altering the format itself. If the number is larger than one, the limit for large numbers will be changed. Likewise, if the number is less than unity the limit for small numbers will be changed.

“#.##” SETNFMT: Passing a single string will change the format for all 3 number ranges to the desired format.

{ 1E100 “#.##” } SETNFMT: A list will change formats for each number range individually. Passing a number and a format string will change the cutoff limit and corresponding format for large or small numbers (depending on the given limit being >1 or <1).

{ 1E-10 “#.##E#” “#.##” } SETNFMT: If the list contains a string without specifying any cutoff limits, the format will be changed in the following order: the first string on the list will change the format for normal numbers, the second one will change small numbers and the third one large numbers. If a format string has a number preceding it, the number will change the cutoff limit, then the string immediately following the number will change the format corresponding to that limit. If a string after has no limit specified, it will follow the order as described. In this example, the list has the number1E-10 therefore it will set the limit for small numbers (since 1E-10 < 1) to the format “#.##E#”. The following string will change the large numbers, since it doesn't have a limit but will follow the sequence “normal → small number → large number”. If there was a string afterwards, it would change the normal numbers. To avoid any ambiguity, it is a good practice to specify the list with the formats in that order, whether they include the cutoff limits or not.

The Format String

  • manual/chapter3/numformatting.1502566172.txt.gz
  • Last modified: 2017/08/12 12:29
  • by claudio