I used below for string formatting in plotly.
texttemplate='%{text:.2f}'
now I like to set num of digit as a variable so I have to use nested string format like this, it didn't work. Thanks for your help.
num_gigit=f(key)
texttemplate='%{text:.{num_digit}f}'