Is there an option to do so as below ?
Current Value
25,482.50 (+0.23%)
Is there an option to do so as below ?
Current Value
25,482.50 (+0.23%)
Hey there, thanks for your question!
If you’re looking to display a metric like “Current Value 25,482.50 (+0.23%)” in Streamlit, the best way is to use st.metric, which supports both number formatting (including thousands separators and currency) and a delta value for the percentage change.
You can use the format parameter to control the number formatting, such as showing commas and decimal places, and the delta parameter for the percentage. For example:
import streamlit as st
st.metric(
label="Current Value",
value=25482.50,
delta=0.23,
format="accounting" # or "dollar", "localized", etc.
)
This will display the value with commas and two decimals, and the delta as a percentage. For more formatting options, see the st.metric documentation.
Sources:
I am looking for displaying the delta value and current value in the same line.
Amit,
use a f string in the value
example:
val = 123
delta =-4
st.metric(
label=f"Current Value {val1} {delta}%",
value=f”val is {val1} del {delta}%,
delta=0.23,
format=“accounting” # or “dollar”, “localized”, etc.
)
first line is label
Second line is value
third line is delta
use f-strings in any
i know this works but i need the delta formatting as well which only happens if we use the delta value but its rendered on next line below the main value