manual:chapter3:numformatting

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
manual:chapter3:numformatting [2021/10/05 07:22]
jojo1973 Revamped. First pass
manual:chapter3:numformatting [2021/10/05 15:29]
jojo1973 [Format localization]
Line 7: Line 7:
 | ''1.23456789123456789E8''  | Using scientific notation  | | ''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.+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 ''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 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 ''[[manual:chapter6:flags:cmd_setnfmt|SETNFMT]]'' command. This command accepts a single string or real number, or a list as arguments: The primary way to change the number formatting is the ''[[manual:chapter6:flags:cmd_setnfmt|SETNFMT]]'' command. This command accepts a single string or real number, or a list as arguments:
Line 23: Line 23:
 | ''"#.##"''  | **Small numbers format:** ''#.##''\\ **Small numbers cutoff:** unchanged\\ **Normal numbers format:** ''#.##''\\ **Large numbers cutoff:** unchanged\\ **Large numbers format:** ''#.##''  | | ''"#.##"''  | **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-10''  | **Small numbers format:** unchanged\\ **Small numbers cutoff:** ''1E-10''\\ **Normal numbers format:** unchanged\\ **Large numbers cutoff:** unchanged\\ **Large numbers format:** unchanged  |
-| ''1E15 "#.#0E" }''  | **Small numbers format:** unchanged\\ **Small numbers cutoff:** unchanged\\ **Normal numbers format:** unchanged\\ **Large numbers cutoff:** ''1E15''\\ **Large numbers format:** ''#.#0E''  |+| ''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''  | | '' "#.###" "#.###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:** ''#.##''  | | ''{ 1E-10 "#.##E#" "#.##" }''  | **Small numbers format:** ''#.##E#''\\ **Small numbers cutoff:** ''1E-10''\\ **Normal numbers format:** unchanged\\ **Large numbers cutoff:** unchanged\\ **Large numbers format:** ''#.##''  |
Line 34: Line 34:
   "#.12#."          @ Normal   "#.12#."          @ Normal
   1E-12 "#.12#.E*"  @ Small numbers (< 1E-12)   1E-12 "#.12#.E*"  @ Small numbers (< 1E-12)
-  1E12 "#.12#.E*"   @ Large numbers (> 1E12)+  1E12 "#.12#.E*"   @ Large numbers (> 1E+12)
 } }
 </code> </code>
Line 44: Line 44:
 ==== The format string ==== ==== 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: 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[radix_point[fractional_part[exponent_part]]]'' +|  ''integer_part[fractional_part][approximation_dot][exponent_part]'' 
-Anything enclosed in ''[ ]'' is optional, the brackets ''< >'' and the vertical bar ''|'' separates mutually exclusive choices and the ellipsis ''...'' means repetition of a character. Now we can proceed examining each part separately.+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.
  
 ---- ----
Line 51: Line 51:
 === The INTEGER part === === The INTEGER part ===
 The //integer part// of the format string has the following format: The //integer part// of the format string has the following format:
-|  ''[+][S[n]]#[.]''  |+|  ''[+][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.  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: Other options to format the integer part of the number are as follows:
  
-  * a preceding ''+'' symbol will force the display of the sign even for positive numbers. The negative sign will always be displayed; +  * a plus sign ''+'' preceding the hash sign will force the display of the sign even for positive numbers. The negative sign will always be displayed; 
-  * the uppercase ''S'' preceding the hash sign indicates the presence of a separator. By default the separator is spaced every 3 digits, but that can be controlled by including the number of digits in each group immediately following the ''S''; for example ''"S4#"'' will add the thousand separator every 4 digits. Valid values for ''S'' are 1 through 15, and the separator character used will be as defined by the command ''[[manual:chapter6:flags:cmd_setlocale|SETLOCALE]]''+  * the uppercase ''S'' preceding the hash sign indicates the presence of a separator. By default the separator is spaced every 3 digits, but that can be controlled by including the number of digits in each group immediately following the ''S''; for example ''"S4#"'' will add the thousand separator every 4 digits. Valid values for ''S'' are ''1'' through ''15'', and the separator character used will be as defined by the command ''[[manual:chapter6:flags:cmd_setlocale|SETLOCALE]]''.
-  * a single trailing dot ''.'' will display the trailing dot for [[manual:chapter3:reals#approximate-versus-exact|approximate]] numbers, while no dot will be shown for [[manual:chapter3:reals#approximate-versus-exact|exact]] numbers.+
  
 ^ Format  ^ Number  ^ Displayed as  ^ ^ Format  ^ Number  ^ Displayed as  ^
Line 64: Line 63:
 | ''+#''  | 123.456  | ''+123''  | | ''+#''  | 123.456  | ''+123''  |
 | ''S4#''  | 123456.789  | ''12 3457''  | | ''S4#''  | 123456.789  | ''12 3457''  |
-| ''S3#.''  | 123456.789  | ''123 457''  |+| ''S3#''  | 123456.789  | ''123 457''  |
  
 ---- ----
Line 70: Line 69:
 === The FRACTIONAL part === === The FRACTIONAL part ===
 The //fractional part// of the format string has the following format: The //fractional part// of the format string has the following format:
-|  ''.<#...|d#|A#>[0][S[n]][.]''  |+|  ''.<#...|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. 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, even if the decimal separator defined by the ''[[manual:chapter6:flags:cmd_setlocale|SETLOCALE]]'' is a different character.+**NOTE**: The format string must use a decimal dot (a.k.a. //radix point//), even if the decimal separator defined by the ''[[manual:chapter6:flags:cmd_setlocale|SETLOCALE]]'' is a different character.
  
 The number of digits desired can be expressed in three different ways: The number of digits desired can be expressed in three different ways:
Line 83: Line 82:
 Various other options are available to format the fractional part of the number: Various other options are available to format the fractional part of the number:
  
-  * when the number of decimal digits is expressed by a repetition of ''#'''s, replacing the last ''#'' with a ''0'' will append trailing zeros as needed to display the requested number of decimal figures. The ''0'' character counts as one additional digit. +  * when the number of decimal digits is expressed by a repetition of ''#'''s, replacing the last ''#'' with a ''0'' will append as many trailing zeros as needed to display the requested number of decimal figures. The ''0'' character counts as one additional digit. 
-  * when the number of decimal digits is expressed by a number followed by a ''#'', a trailing ''0'' still indicates that trailing zeros need to be added **but** in this case the presence of the zero does not add another digit. +  * when the number of decimal digits is expressed by a number //d// followed by a ''#'', a trailing ''0'' still indicates that trailing zeros need to be added **but** in this case the presence of ''0'' does not add another digit. 
-  * the uppercase ''S'' following the last ''#'' or ''0'' indicates the presence of a separator. By default the separator is spaced every 3 digits, but that can be controlled by including the number of digits in each group immediately following the ''S''; for example ''"S4#"'' will add the fractional separator every 4 digits. Valid values for ''S'' are 1 through 15, and the separator character used will be as defined by the command ''[[manual:chapter6:flags:cmd_setlocale|SETLOCALE]]''.\\ **NOTE**: the number of digits in a group must match between the integer and fractional part of the number, it's an invalid format string to request separators every //n// digits on the integer part, and //m// digits on the fractional part when //m≠n//+  * the uppercase ''S'' following the last ''#'' or ''0'' indicates the presence of a separator. By default the separator is spaced every 3 digits, but that can be controlled by including the number of digits in each group immediately following the ''S''; for example ''"S4"'' will add the fractional separator every 4 digits. Valid values for ''S'' are ''1'' through ''15'', and the separator character used will be as defined by the command ''[[manual:chapter6:flags:cmd_setlocale|SETLOCALE]]''.\\ **NOTE**: the number of digits in a group must match between the integer and fractional part of the number, it's an invalid format string to request separators every //n// digits on the integer part, and //m// digits on the fractional part when //m≠n//.
-  * a single trailing dot ''.'' will display the trailing dot for [[manual:chapter3:reals#approximate-versus-exact|approximate]] numbers, while no dot will be shown for [[manual:chapter3:reals#approximate-versus-exact|exact]] numbers.\\ **NOTE**: the approximate dot cannot be included twice in the format string, i.e. if the string has both integer and fractional parts then the dot must be appended only to the latter.+
  
 ^ Format  ^ Number  ^ Displayed as  ^ ^ Format  ^ Number  ^ Displayed as  ^
Line 94: Line 92:
 | ''#.###0''  | 123.45  | ''123.4500''  | | ''#.###0''  | 123.45  | ''123.4500''  |
 | ''#.4#0''  | 123.45  | ''123.4500''  | | ''#.4#0''  | 123.45  | ''123.4500''  |
-| ''#.A#.''  | 123.45.  | ''123.45.'' +| ''#.8#0S4''  | 123.45  | ''123.4500 0000''  | 
-| ''#.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 [[manual:chapter3:reals#approximate-versus-exact|exact]] or [[manual:chapter3:reals#approximate-versus-exact|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 ''[[manual:chapter6:flags:cmd_setlocale|SETLOCALE]]'' can change the appearance of the decimal separator only. 
 + 
 +^ Format  ^ Number  ^ Displayed as  ^ 
 +| ''#.####'' 123.45678 | ''123.4568'' 
 +| ''#.####.''  | 123.45678.  | ''123.4568.''  |
  
 ---- ----
Line 110: Line 123:
 Various other options are available to format the exponent part of the number: Various other options are available to format the exponent part of the number:
  
-  * an asterisk ''*'' following the exponent letter will suppress the exponent in scientific notation when the exponent is zero;+  * an asterisk ''*'' following the exponent letter will suppress the exponent in scientific notation when the exponent is ''0'';
   * a plus sign ''+'' after the exponent letter will force the exponent sign for positive exponents. Negative exponents are always displayed with the sign;   * a plus sign ''+'' after the exponent letter will force the exponent sign for positive exponents. Negative exponents are always displayed with the sign;
-  * when the preferred exponent is expressed as a hash symbol ''"'', it activates engineering notation. The displayed number will have an exponent multiple of 3, chosen by the system to ensure the integer part of the mantissa is between ''1'' and ''999''. +  * when the hash symbol ''#'' is present after the exponent letter, it activates engineering notation. The displayed number will have an exponent multiple of 3, chosen by the system to ensure the integer part of the mantissa is between ''1'' and ''999''; 
-  * when a number is present after the exponent letter, it activates engineering notation and indicates a preferred exponent. All numbers will display using the requested exponent. The preferred exponent can be in the range ''-21'' to ''+21'', and has to be a __multiple of 3__. When using engineering notation with a preferred exponent, the asterisk will **always** suppress the exponent and not only when it'zero.+  * when a number is present after the exponent letter, it activates engineering notation and indicates a preferred exponent. All numbers will display using the requested exponent. The preferred exponent can be in the range ''-21'' to ''+21'', and has to be a __multiple of 3__.\\ **NOTE**: When using engineering notation with a preferred exponent, the asterisk will **always** suppress the exponent and not only when it'''0''
 + 
 +^ 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 ''[[manual:chapter6:flags:cmd_setnfmt|SETNFMT]]'' command allows great customization with respect to the grouping of digits in the integer and fractional parts of the number; the command ''[[manual:chapter6:flags:cmd_setlocale|SETLOCALE]]'' allows customization of the characters that delimit these groupings. 
 + 
 +''[[manual:chapter6:flags:cmd_setlocale|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 [[manual:chapter3:reals#approximate-versus-exact|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 ''[[manual:chapter6:flags:cmd_getlocale|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:
  
 +  * **ON<sup>hold</sup>-SP** cycles thru number format presets;
 +  * **ON<sup>hold</sup>-DOT** cycles thru localization presets;
 +  * **ON<sup>hold</sup>-{1...9}** selects the length of the fractional part in scientific or engineering mode;
 +  * **ON<sup>hold</sup>-{MUL/DIV}** switches to engineering mode and selects ''Auto'' (no preferred exponent) or a preferred exponent in the range ''-21'' to ''21'' in steps by 3.
 +\\ \\ 
 +**__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) | '';'' |
  • manual/chapter3/numformatting.txt
  • Last modified: 2021/10/05 15:29
  • by jojo1973