# 26. Pad a Number with Leading Spaces

# Description

Pads the left side of a number with spaces so that the decimals will align properly.

# Code

"«NumberVar:9999.99»"

IF POSITION( RESULT , "." ) = 7

" " + RESULT

ELSE IF POSITION( RESULT , "." ) = 6

" " + RESULT

ELSE IF POSITION( RESULT , "." ) = 5

" " + RESULT

ELSE IF POSITION( RESULT , "." ) = 4

" " + RESULT

ELSE IF POSITION( RESULT , "." ) = 3

" " + RESULT

ELSE IF POSITION( RESULT , "." ) = 2

" " + RESULT

ELSE IF POSITION( RESULT , "." ) = 1

" " + RESULT

END IF

# Explanation

This computation pads the left side of a number with as many spaces as necessary to decimal-align the number with other numbers in a column.

The number variable NumberVar is first converted into a string. Then, using the POSITION model, we determine where the decimal falls in the string. By the decimal's position in the string we can determine how many spaces need to be added before the number.

This computation assumes a string that is ten characters long, including the decimal.