title: Using variable to specify floating point precision of hover text in plotly using python
body: <p>I would like to pass a variable, in this case <code>precision</code> for defining the floating points in plotly <code>hovertemplate= &quot;%{y:.2f}</code>.</p>
  <p>Is there a way of doing this? Below is a working sample code</p>
  <pre><code>import pandas as pd
  import plotly.express as px
  import plotly.io as pio
  
  pio.renderers.default = &quot;notebook_connected&quot;
  
  df = pd.DataFrame(dict(a=[1,2,3,4,5], b=[0.1,0.22,0.333, 0.4444, 0.55555]))
  precision = 2
  fig = px.line(df, x=&quot;a&quot;, y=&quot;b&quot;)
  
  #         
  fig.update_traces(mode=&quot;lines&quot;, hovertemplate= &quot;%{y:.3f}&quot;, hoverinfo=&quot;x + y&quot;) 
  # would like to use a variable to define floating point precision
  # Something  like: hovertemplate= &quot;%{y:.precisionf}&quot;
  
  fig.update_layout(
     template=&quot;plotly_white&quot;,
     title='Sample Plot',
     xaxis_range= [0, 6],
     
     xaxis=dict(
         tickmode=&quot;linear&quot;,
         dtick=1,
         mirror=True,
         ticks=&quot;outside&quot;,
         showline=True,
         linewidth=1,
         linecolor=&quot;#A6C4EF&quot;,
     ),
     yaxis=dict(
         tickmode=&quot;linear&quot;,
         tick0=5,
         dtick=0.1,
         mirror=True,
         ticks=&quot;outside&quot;,
         showline=True,
         linewidth=1,
         linecolor=&quot;#A6C4EF&quot;,
     ),
     
     xaxis_title='a',
     yaxis_title='b',
     legend_title=&quot;LEGEND&quot;,
     legend=dict(bordercolor=&quot;#A6C4EF&quot;, borderwidth=1),
     hovermode=&quot;x unified&quot;,
  )
  
  fig.show()
  
  </code></pre>