Converts a number, boolean, string or array to text, optionally through a format pattern or a format.* constant.
str.tostring turns a value into a string. Booleans become true or false, strings pass through, and an array becomes its items in square brackets, separated by commas.
A number prints with up to eight decimals and no trailing zeros unless you pass a format. The format is either a pattern such as "#.##" or "0.000", or one of format.price, format.mintick, format.percent and format.volume.
Syntax
str.tostring(value: series int/float/bool/string/enum/array<int/float/bool/string>/matrix<int/float/bool/string>) -> series string
str.tostring(value: simple int/float/bool/string/enum) -> simple string
str.tostring(value: const enum) -> const string
str.tostring(value: series int/float/array<int/float>/matrix<int/float>, format: series string) -> series string
str.tostring(value: simple int/float, format: simple string) -> simple stringArguments
| Name | Type | Default | Description |
|---|---|---|---|
| value | series int/ | required | The value to convert: a number, bool, string, enum or an array of them. |
| format | simple/ | required | A number pattern, or a format.* constant. Digits in the pattern set the decimals shown, 0 forces a digit and # shows one only when needed. |
Returns
const/simple/series string: the value as text.
Remarks
format.pricerounds to the symbol's decimals,format.mintickrounds to the tick size,format.percentshows two decimals with a percent sign, andformat.volumeabbreviates with K, M and B.- An na number becomes the text NaN.
- On Sidechair: a pattern follows Java DecimalFormat rules, so "#.##" prints 3 for 3.001 and a result that rounds to zero carries no minus sign.
Example
//@version=6
indicator("Close as text")
txt = str.tostring(close, "#.00")
plot(str.length(txt), "Characters", color = color.blue, style = plot.style_stepline)
plot(str.tonumber(str.tostring(close, format.mintick)), "Rounded close", color = color.orange)See also
Runs on Sidechair