str.tonumber

Reads a number out of a string. The result is a float in every form, so a string holding a whole number still comes back as a float.

str.tonumber(const string source) → const float
str.tonumber(input string source) → input float
str.tonumber(series string source) → series float
str.tonumber(simple string source) → simple float
ParameterTypeRequiredDescription
sourceconst stringyesthe string to read a number from

Returns const float or input float or series float or simple float — A series float, or na where the text does not parse as a number. It does not raise, and it does not return zero.

indicator("A number read from text")
plot(str.tonumber("42.5"))

See also str.contains · str.endswith · str.format_time

Part of the function index.

Ready to put this into practice?
Try GoCharting Premium
Unlock advanced orderflow, market profile, options desk, and real-time data — everything you just read about, live in your charts.
Upgrade