Table of Contents

Displaying and formatting numbers

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 thousands separators and also grouping the fractional digits
1.23456789123456789E8 Using 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 (a.k.a. normal numbers in this discussion).

The default configuration presents numbers less than 1E-12 in scientific notation, numbers greater than 1E+12 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:

Here are some examples:

SETNFMT argument Effect
“#.##” Small numbers format: #.##
Small numbers cutoff: unchanged
Normal numbers format: #.##
Large numbers cutoff: unchanged
Large numbers format: #.##
1E-10 Small numbers format: unchanged
Small numbers cutoff: 1E-10
Normal numbers format: unchanged
Large numbers cutoff: unchanged
Large numbers format: unchanged
{ 1E+15 “#.#0E” } Small numbers format: unchanged
Small numbers cutoff: unchanged
Normal numbers format: unchanged
Large numbers cutoff: 1E+15
Large numbers format: #.#0E
{ “#.###” “#.###0E” “#.#0E”} Small numbers format: #.###0E
Small numbers cutoff: unchanged
Normal numbers format: #.###
Large numbers cutoff: unchanged
Large numbers format: #.#0E
{ 1E-10 “#.##E#” “#.##” } Small numbers format: #.##E#
Small numbers cutoff: 1E-10
Normal numbers format: unchanged
Large numbers cutoff: unchanged
Large numbers format: #.##

Regarding the last example, the first element is 1E-10 therefore the string immediately following will set the format for small numbers (since 1E-10 < 1) to #.##E#. The following string will change the large numbers, since no limit is specified and therefore the sequence normal → small numbers → large numbers is followed. If there were a third string afterwards, it would have changed 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 default format is:

{
  "#.12#."          @ Normal
  1E-12 "#.12#.E*"  @ Small numbers (< 1E-12)
  1E12 "#.12#.E*"   @ Large numbers (> 1E+12)
}

Current format list can be retrieved using the GETNFMT command.


The format string

The format string defines how a number is displayed; in its basic form is very simple, but the syntax allows for great flexibility and its appearance can become a bit cryptic… at a first glance the structure of the string is:

integer_part[fractional_part][approximation_dot][exponent_part]

Anything enclosed in [ ] is optional, the brackets < > and the vertical bar | separate mutually exclusive choices and the ellipsis means repetition of a character. Now we can proceed examining each part separately.


The INTEGER part

The integer part of the format string has the following format:

[+][S[n]]#

The simplest format string is just the hash sign “#”. In fact that's the only mandatory part: a single # represents the entire integer part of the number, as many digits as needed.

Other options to format the integer part of the number are as follows:

Format Number Displayed as
# 123.456 123
+# 123.456 +123
S4# 123456.789 12 3457
S3# 123456.789 123 457

The FRACTIONAL part

The fractional part of the format string has the following format:

.<#…|d#|A#>[0][S[n]]

To display the fraction part of the number, the string needs to include a decimal dot and at least one # symbol.

NOTE: The format string must use a decimal dot (a.k.a. radix point), even if the decimal separator defined by the SETLOCALE is a different character.

The number of digits desired can be expressed in three different ways:

Various other options are available to format the fractional part of the number:

Format Number Displayed as
#.#### 123.45678 123.4568
#.4# 123.45678 123.4568
#.A# 123.45678 123.45678
#.###0 123.45 123.4500
#.4#0 123.45 123.4500
#.8#0S4 123.45 123.4500 0000

The APPROXIMATION dot

The approximation dot part of the format string has the following format:

[.]

In newRPL the real numbers can be represented as exact or approximate, the latter property indicated by a trailing dot . following the fractional (or just the integer, if missing) part of the number.

It is possible to turn on or off the display of the approximation dot adding a single dot . character just after the integer and fractional part of the format.

NOTE: the approximation dot is always displayed as a dot: the command SETLOCALE can change the appearance of the decimal separator only.

Format Number Displayed as
#.#### 123.45678. 123.4568
#.####. 123.45678. 123.4568.

The EXPONENT part

The exponent part of the format string has the following format:

<E|e>[*][+][<n|#>]

To display a number in scientific or engineering notation (with an optional preferred exponent) the exponent letter E or e is included in the format string after the fractional part. The difference between the two notations is the following:

Various other options are available to format the exponent part of the number:

Format Number Displayed as
#.##.E 0.01234. 1.23.E-2
#.##.e 0.01234. 1.23.e-2
#.##.E 3.5 3.5E0
#.##.E+ 3.5 3.5E+0
#.##.E* 3.5 3.5
#.##.E+# 35150 35.15E+3
#.##.E+3 35 0.04E+3
#.##.E*+3 35 0.04

Format localization

The SETNFMT command allows great customization with respect to the grouping of digits in the integer and fractional parts of the number; the command SETLOCALE allows customization of the characters that delimit these groupings.

SETLOCALE accepts a 4-character string which defines what character must be used for each grouping: the following table shows the default setting.

Position Character Function Notes
1 . Decimal separator This is the character used to divide the integer part of a number from the fractional part. This character is NOT the same as the approximation dot which is always displayed as a dot.
2 U+2009
(thin space)
Integer separator This is the character used to divide the digits groups in the integer part of a number.
3 U+2009
(thin space)
Fractional separator This is the character used to divide the digits groups in the fractional part of a number.
4 , Arguments separator This is the character used to divide the arguments of a symbolic function (e.g. 'GCD(16,32)') or the real and imaginary parts of a complex number (e.g. (1,-2)).

The GETLOCALE command returns on the stack the localization string.


Preset formats

A different, user friendly way to change the display of numbers is to use the preset formats that are provided by newRPL. These presets are quickly accessed via the keyboard and can be combined in many different ways:



Base number format presets

Preset name Small numbers format Small numbers cutoff Normal numbers format Large numbers cutoff Large numbers format
STD #.12#.E* 1E-12 #.12#. 1E+12 #.12#.E*
FIX #.12#.E* 1E-12 #.12#0. 1E+12 #.12#.E*
SCI #.12#.E* 1E-12 #.12#.E 1E+12 #.12#.E*
ENG #.12#.E* 1E-12 #.12#.E*# 1E+12 #.12#.E*



Base localization presets

Preset name Integer grouping Fractional grouping Decimal separator Integer separator Fractional separator Arguments separator
1000.000000 No No . U+2009
(thin space)
U+2009
(thin space)
,
1,000.000000 Yes No . , U+2009
(thin space)
;
1 000.000000 Yes No . U+2009
(thin space)
U+2009
(thin space)
,
1000.000 000 No Yes . U+2009
(thin space)
U+2009
(thin space)
,
1,000.000 000 Yes Yes . , U+2009
(thin space)
;
1 000.000 000 Yes Yes . U+2009
(thin space)
U+2009
(thin space)
,
1000,000000 No No , U+2009
(thin space)
U+2009
(thin space)
;
1.000,000000 Yes No , . U+2009
(thin space)
;
1 000,000000 Yes No , U+2009
(thin space)
U+2009
(thin space)
;
1000,000 000 No Yes , U+2009
(thin space)
U+2009
(thin space)
;
1.000,000 000 Yes Yes , . U+2009
(thin space)
;
1 000,000 000 Yes Yes , U+2009
(thin space)
U+2009
(thin space)
;