NumToStr
- convert number to string

String manipulation
(AmiBroker 4.50)


SYNTAX NumToStr( NUMBER, format = 1.3, separator=True, roundAndPad = False )
NumToStr( ARRAY, format = 1.3, separator=True, roundAndPad = False )
RETURNS STRING
FUNCTION It is used to convert numeric value of NUMBER or ARRAY to string.

The second parameter - format - allows you to control output formatting (decimal places and leading spaces). The integer part of the number controls minimum number of characters used to display the number (if you specify high number the output will be space-padded). The fractional part defines how many decimal places to display, for example 1.0 - will give you a number without fractional part at all, and 1.2 - will give two digits past the decimal point

There is also a special format constant formatDateTime that allows to convert date/time returned by DateTime() function formatted according to Windows regional settings.

Since 6.20 also supported is formatDateTimeISO which will return date time in international format (ISO) i.e, YYYY-MM-DD HH:MM:SS

Third parameter separator (true by default) controls if thousand separator is added or not.
Thousands separator is definable in Tools->Preferences->Misc.

Fourth parameter roundAndPad controls whenever function rounds output beyond 7th significant digit (and pads the rest with zeros), By default rounding is OFF now because it was off in 5.90 and earlier and rounding introduced in 5.91 could confuse old time users

Note: NumToStr is a synonym for WriteVal function.

EXAMPLE 1. Simple use (no custom format)

printf( NumToStr( StochK(39) - StochK(12)) );

2. Display rate of change with 2 decimal digits and % appened to the end

printf( NumToStr( ROC( Close, 20 ), 1.2 ) + "%%");

3. Display date/time according to regional settings


printf( NumToStr( DateTime(), formatDateTime ));

SEE ALSO WRITEVAL() function , StrToNum() function , DateTimeFormat() function

References:

The NumToStr function is used in the following formulas in AFL on-line library:

More information:

See updated/extended version on-line.