Format                                                                                                   Functions

 

FORMAT( numVar as anyNumType,  fmtstring as String)

 

Returns: A formatted text string

 

Description

To format numeric data into text strings suitable for display or printing. NumVar is any numeric format including integer, short, float, or double. Fmtstring is a string which controls the formatting of the numeric data. The variable being assigned to should be padded with enough characters to receive the result. fmtstring may contain one or more of the following characters:

 

0

replaced by a digit from the number if available or zero if not

n

replaced by a digit from the number if available or space if not

#

replaced by a digit from the number if available or nothing if not

.

places a decimal point in the output text

+

Replaced by a minus sign if the number is negative or space if positive

-

Replaced by a minus sign if the number is negative or space if positive

,

places a comma in the output string if a leading digit has been encountered or a space if not.

 

Any other character is copied into the output stream

 

Example

Dim a as double

Dim b as double

Dim c as double

Dim i as integer

Dim j as integer

Dim k as Integer

Dim s as String

a=123.45

b=-37.65

c= 12345.6

i=92

s="         "

s=Format(a, "#####.000" ) 'result= 123.450  (length=7 because # does not reserve a blank if there is no leading digit)

s=Format(a, "nnnnn.000" ) 'result=123.450(length=9 because n reserves a blank if there is no leading digit)

 

s=Format(a, "-00000.000") 'result=  00123.450 (minus is ignored because the number is negative)

s=Format(b,"+nn,nnn.0") 'result is -37.6  

s=Format(c, "nn,nnn.00") 'result is 12,345.60

s=Format(i, "###%")    'result is 92%