WriteVal
- converts number to string

Exploration / Indicators


SYNTAX WriteVal( NUMBER, format = 1.3, separator=True, roundAndPad = False )
WriteVal( ARRAY, format = 1.3, separator=True, roundAndPad = False )
RETURNS STRING
FUNCTION THIS FUNCTION IS OBSOLETE. Use functionally identical NumToStr() instead.

It is used to convert numeric value of NUMBER or ARRAY to string. It does NOT write anything, it simply returns a string that can be used in other operations or as a text column in exploration or displayed using printf().

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.

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 and NumToStr is preferred in new coding.

EXAMPLE printf( WriteVal( Close, 1.3, True ) );

For more examples see NumToStr function

SEE ALSO WRITEIF() function , DATETIME() function , NumToStr() function

Comments:

Tomasz Janeczko
tj --at-- amibroker.com
2004-06-12 05:53:06
WriteVal always returns *one* value of the array
(not arrays of values). In almost all cases this is LastValue
of the array but in indicators it is "selected value" -
the one that is selected by the vertical line.
Tomasz Janeczko
tj --at-- amibroker.com
2004-06-12 05:54:45
The name WriteVal() is here because people coming from Metastock wanted easy translation from MS that has WriteVal function too.
Better name for it is Num2Str.

References:

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

More information:

See updated/extended version on-line.