1. Home
  2. DECIMALS procedure

DECIMALS procedure

Sets the number of decimals for a structure, using its round-off (A. Keen).


SETATTRIBUTE = string token Attributes to be redefined for STRUCTURE (decimals); default deci
SIGNIFICANTFIGURES = scalar Required number of significant figures; default takes the system default, which can be modified by SET


STRUCTURE = identifiers Numerical structure for which the number of decimals is to be set
DECIMALS = scalars To save the number of decimals to use for all the values of each structure
ROUND = scalars To save the round-off provided by using DECIMALS decimal places
VDECIMALS = structures To save numbers of decimals for every value of each structure
VROUND = structures To save the round-off for every value of each structure


The number of decimals that Genstat uses as a default when printing a numerical structure is calculated as the number required to display the mean of the absolute values of the numbers in the structure to a standard number of significant figures (see the PRINT directive). Usually the standard number of significant figures is four, but this “system default” can be changed using the SIGNIFICANTFIGURES option of the SET directive. This default allows output to be generated automatically with reasonable accuracy. However, it may be preferable to use fewer decimals if the numbers can be represented exactly with three or fewer significant figures. For example it may be preferable to use two decimal places rather than four for a variate containing the values 0.1 and 0.21 (i.e. to print 0.10 and 0.21, rather than 0.1000 and 0.2100).

The DECIMALS procedure operates similarly to the standard Genstat default, except that the number of decimal places is decreased if the final decimal position would contain the digit zero for every value of the structure. It also differs in that it has its own SIGNIFICANTFIGURES option to specify the required number of significant figures from the system default.

The numerical structure for which the number of decimals is to be determined must be supplied using the STRUCTURE parameter. The DECIMALS parameter can save the appropriate number of decimal places (as a scalar), and parameter ROUND can save the maximum round-off over the values of the structure (see Method). By default DECIMALS modifies the declaration of the STRUCTURE so that this becomes its default number of decimal places for subsequent printing (see the DECIMALS parameter of SCALAR, VARIATE, TABLE, MATRIX and SYMMETRICMATRIX). However, you can set option SETTATTRIBUTE=* if you want the default number of decimals to remain unchanged.

DECIMALS can also calculate a separate number of decimal places for each of the values of the STRUCTURE. This can be saved (in a structure of the same type as the STRUCTURE) using the VDECIMALS parameter, and the round-off for each value can similarly be saved using the VROUNDOFF parameter.



The round-off value of a number equals 10k with k a negative or positive integer or zero. The round-off value of a number equals d if the number after dividing by d is an integer but after dividing by 10 × d is not. If the round-off value is such that the number of significant digits is greater than 4, the round-off value is increased correspondingly. For example, the round-off value of 880 equals 10, that of 0.2300 equals 0.01 and of 9999.11 equals 1. The round-off value of a structure is the minimum of the round-off values of all the elements of the structure, subject to the restriction that the number of significant digits does not exceed 4 for any of the values of the structure.

The number of decimals of a structure is calculated from the round-off value of the structure as -log10(round-off value), with minimum value zero. So in the above examples the number of decimals equals 0 for 880, 2 for 0.2300 and 0 for 9999.11.

Action with RESTRICT

Restrictions are ignored.

See also

Directives: PRINT, SET.
Commands for: Input and output, Data structures.


CAPTION   'DECIMALS example'; STYLE=meta
MATRIX    [ROWS=2; COLUMNS=3] ymat; VALUES=!(1 ... 6)
PRINT     ymat
PRINT     ymat
VARIATE   a; VALUES= !(9, 20, 30 ... 100)
VARIATE   b; VALUES= !(.01, .02 ... .1)
VARIATE   c; VALUES= !(.01, .02 ... .09, .102)
VARIATE   d; VALUES= !(100, 110 ... 180, 190.111)
PRINT     a,b,c,d
DECIMALS  a,b,c,d; DECIMALS=nda,ndb,ndc,ndd; ROUND=da,db,dc,dd
PRINT     a,b,c,d
&         da,db,dc,dd
&         nda,ndb,ndc,ndd
Updated on September 13, 2019

Was this article helpful?