NumToString(12345.5, "10.2fS") // Returns " 12 345.50" (the thousand separator is " ")

NumToString(12345.5, "10,2fS") // Returns " 12 345,50" (the decimal separator is ",")

Syntax

<Result> = NumToString(<Number> [, <Format>])

<Result>: Character string

Number expressed in character string format according to the selected format. If <Number> is a string, this string is returned as it is. The format is ignored.

If <Number> is a string, this string is transformed as if it was a number.

<Number>: Integer or real

Numeric value to convert into a character string (according to the specified format).

<Format>: Optional character string or constant

Format of character string, expressed in the following format:

If this parameter is specified, justifies the number to the left (<Alignment> = "-"). The number is justified to the right by default.

<Sign>

If this parameter is specified, forces the sign for the positive numbers (<Sign> = "+"). This sign will appear on the left of the first significant number. By default, only the negative numbers have a "-" sign on the left of the first significant number. Special case: if this parameter is specified and if the number is equal to 0, the "+" sign will be displayed. Same if a negative number becomes equal to 0.

<Zero>

If this parameter is specified (<Zero> ="0"), the number will be completed with zero on the left of the first significant number if the significant part of the number is smaller that the requested size and the number is right justified. By default, the number is not filled with "0". For example: NumToString(123, "05d") will return "00123".

<Size>

Defines the total length of the result string. The total length corresponds to the following elements: sign, thousand separator, decimal point, exponent, integer and decimal parts of the number. This size must be less than 100. If the specified size is too small to contain the significant part of the number, it will be ignored. By default, the number will have the size of its significant part (it cannot be filled with zeros). Same if <Size> = 0. If the specified size is greater than the significant part of the number:

the result string will be filled with space characters on the right if the number is justified to the left,

the result string will be filled with space characters or zeros on the left if the number is justified to the right.

Defines the total length of the result string or the total length of the integer part if the number is filled with zeros. The total length corresponds to the following elements: sign, thousand separator, decimal point, exponent, integer and decimal parts of the number. If the specified size is too small to contain the significant part of the number, it will be ignored. By default, the number will have the size of its significant part (it cannot be filled with zeros). Same if <Size> = 0. If the specified size is greater than the significant part of the number:

the result string will be filled with space characters on the right if the number is justified to the left,

the result string will be filled with space characters or zeros on the left if the number is justified to the right.

<.Precision>

Defines the decimal separator ("." or "," characters) and the number of decimal places (for the float ("f") and exponent ("e") <Types> only).

The decimal separator:

If the decimal separator is a comma, the decimal separator will be the one defined:

in the linguistic parameters of Windows.

in the Windows configuration of the server.

for the current user.

If the decimal separator is a dot, the decimal separator used will be a dot.

Notes:

ChangeSeparator has no effect on this separator. Indeed, this function acts on the display mask of numeric values in the controls.

The <,Precision> syntax cannot be used: you must use <.Precision>.

Number of decimals:

The number of decimal places must be less than 100.

If the number of decimal places in the number is greater than <Precision>, the decimal part is rounded to the specified number of decimal places.

If the number of decimals in the number is less than <Precision>, the decimal part is filled with "0" to the right.

The value of <Precision> can be greater than <Size>. In this case, <Size> is ignored.

Defines the number of decimals (for the float ("f") and exponent ("e") <Types> only).

If the number of decimal places in the number is greater than <Precision>, the decimal part is rounded to the specified number of decimal places.

If the number of decimals in the number is less than <Precision>, the decimal part is filled with "0" to the right.

The value of <Precision> can be greater than <Size>. In this case, <Size> if ignored if the number is filled with space characters.

<Type>

Type of the result, mandatory parameter:

d: Integer: A real number will be rounded to the nearest integer.

e: Exponential notation: If <Precision> is not indicated, 6 digits by default.

f: Decimal notation: If <Precision> is not indicated, 6 digits by default.

x and X: Hexadecimal notation (X for uppercase letters): Only the integer part of the number is taken into account (no rounding). Special case: 1. Size not specified and negative number: 20 hexadecimal characters for a currency, 8 characters for all the other numeric types. 2. Negative number: the size of the result string will be at least the size allowing to specify the sign bit. For example: -32767 if the "3X" format will return "8001"

o: Octal notation: Only the integer part of the number is taken into account (no rounding). Special case: 1. Size not specified and negative number: 27 hexadecimal characters for a currency, 11 characters for all the other numeric types. 2. Negative number: the size of the result string will be at least the size allowing to specify the sign bit. For example: -32767 in the "3o" format will return "700001"

<Thousand>

Thousand separator (<Thousand> = "S" or "s"). The digits found in the integer part of the number will be grouped by 3 and separated by the thousands separator defined in Windows. If the sign is present, it will always be displayed immediately to the left of the first significant digit. No thousands separator can be found between the sign and the first digit.

The thousands separator is always a space character (' ').

Limits

The "f" format returns a valid result for numbers included between -1e+17 and 1e+17.

"x", "d" or "o" formats: the integer part must not exceed 99 999 999 999 999 999.

How to use a comma for the decimal separator? If the Windows configuration on the server is not using a comma as decimal separator, you have the ability to:

use a numeric edit control (hidden if necessary). The displayed value can be retrieved by ..DisplayedValue.

use a Formatted Display control.

Conversion into bytes

Versions 16 and later To convert a size into bytes, use LengthToString.

New in version 16 To convert a size into bytes, use LengthToString.