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 09:37]
jojo1973 [The format string]
manual:chapter3:numformatting [2021/10/05 15:29] (current)
jojo1973 [Format localization]
Line 9: Line 9:
 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). 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 82: 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 ''0'' 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//.
  
Line 92: Line 92:
 | ''#.###0''  | 123.45  | ''123.4500''  | | ''#.###0''  | 123.45  | ''123.4500''  |
 | ''#.4#0''  | 123.45  | ''123.4500''  | | ''#.4#0''  | 123.45  | ''123.4500''  |
-| ''#.8#0S4''  | 123.45 | ''123.4500 0000.''  |+| ''#.8#0S4''  | 123.45  | ''123.4500 0000''  |
  
 ---- ----
Line 141: Line 141:
  
 ==== Format localization ==== ==== 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.1633451874.txt.gz
  • Last modified: 2021/10/05 09:37
  • by jojo1973