如何移除图表标签的百分号并设置默认显示保留两位小数
移除图表标签中的百分号解决方案
方法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
相关产品推荐
相关产品推荐

