How to make integer alignment for texts?

To provide integer alignment of texts the values which needed to be displayed should be converted into string types. After that, the location of the decimal point within each string is needed to be known, to define the exact horizontal starting positions for the strings.

In the following example the actual Area, Volume, Width, Depth and Height values are displayed of a block. The value column is aligned by the integer parts of the values, the decimal points and the fractions after it are positioned in the middle of the width of the block.

First the conversion to string types should be done. For the Area and the Volume values variables are used to store the calculated values, for the side lengths of the block the parameter values are directly used in the STR function. Various formats of the values can be displayed, for further information see the STR function in GDL Reference Guide.

The visualization of the decimal point depends on the settings of the operation system, so the certain way to know the actual decimal point character is to create a parameter for it which is available for the user. In the following example this parameter’s name is “stSepChar”.

For getting the location of the decimal point, the STRSTR function is used. It returns an integer number, which indicates the position of the decimal point among the characters within the string value. If there is no decimal point in the string value, the STRSTR function returns 0. In this case the text should be indented by the whole string. The STRSUB function is used for getting the part of the string from the beginning to the decimal point. In this example the decimal point is not included in the horizontal positioning, therefore the integer position of it should be subtracted by 1. The STW function returns the length of the substring in millimeters (paper size). The horizontal position is calculated from the middle of the block (blockWidth / 2), by a subtraction of the length of the integer part in model size.