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

如何移除图表标签的百分号并设置默认显示保留两位小数

移除图表标签中的百分号解决方案
  • 方法1:手动计算数值,不用自动加百分号的格式
    原来的format.percent会自动给数值加上百分号,你可以把above_perc乘以100,然后用普通数值格式输出,比如用format.mintick(适配图表最小变动单位),或者指定固定小数位数。修改后的代码:

    if show_open_high == true
        label.new(current_bar_index, h + distance, style = label.style_none, text = (positive_sign) + str.tostring(above_perc * 100, format = format.mintick), textcolor = open_high_color)
    

    要是需要固定显示2位小数,把格式改成"0.00"就行:

    if show_open_high == true
        label.new(current_bar_index, h + distance, style = label.style_none, text = (positive_sign) + str.tostring(above_perc * 100, format = "0.00"), textcolor = open_high_color)
    
  • 方法2:生成字符串后替换掉百分号
    先按原来的逻辑生成带百分号的文本,再用str.replace把%替换成空字符串,这样也能去掉百分号:

    if show_open_high == true
        percent_text = str.tostring(above_perc, format = format.percent)
        clean_text = str.replace(percent_text, "%", "")
        label.new(current_bar_index, h + distance, style = label.style_none, text = (positive_sign) + clean_text, textcolor = open_high_color)
    

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.22 13:45:55