Search code examples
stringpine-scriptdecimalformat

How do I plot 5.234 as 5.2 and 5 as 5.0 in Pine script ? I basically want to show 1 digit after decimal point, even if it is a zero


How do I plot 5.234 as 5.2 and 5 as 5.0 in Pine script ? I basically want to show 1 digit after decimal point, even if it is a zero. Please Help.

It tried str.tostring(num, "#.#")

It works fine for let's say when num = 5.234 but it doesn't work when num = 5


Solution

  • Try :

    str.tostring(num, "#.0")
    

    This will force the 0 to show up.