You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Pine Script中str.tonumber()函数行为不一致问题咨询

Pine Script str.tonumber() 参数传递转换异常问题

现象描述

在Pine Script v5环境下,str.tonumber('15min')在函数内部直接定义字符串时可正确转换为15.00,但将该字符串作为函数参数传入时,转换失败返回NaN。此问题已提交官方Bug报告。

复现代码

//@version=5
indicator("My script", "m", true)

convert() =>
    foo = '15min'
    str.tostring(str.tonumber(foo))

convert(simple string foo) => str.tostring(str.tonumber(foo))

if barstate.islast
    label.new(bar_index, high * 1.001, 'Correct result: ' + convert()) // 正确返回15
    foo = '15min'
    label.new(bar_index, high, 'Inconsistent result: ' + convert(foo)) // 返回NaN

关键差异

  • 无参数版本convert():函数内直接声明的'15min'字符串,str.tonumber()可正常提取数字部分完成转换
  • 带参数版本convert(simple string foo):传入相同字符串时,str.tonumber()无法解析数字,返回NaN

内容的提问来源于stack exchange,提问作者elod008

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.10 22:30:58