Use st.number_input when an app needs a user to enter a numeric value with built-in limits and step controls. It works like st.text_input, but adds minimum and maximum values plus buttons for increasing or decreasing the value. section 3.7.1
Let users choose decimal places
In a unit converter, collect the preferred number of decimal places with a default of 3 and a minimum of 0: places = st.number_input("Decimal places to round to", value=3, min_value=0) The returned places value can then control rounding. The - and + buttons change the value by 1 by default; pass step to choose a different interval. section 3.7.1
Choose the widget according to the kind of number your interface collects:
- Use min_value to reject values below an allowed boundary; entering a negative number of decimal places shows an error. section 3.7.1
- Use step when the default one-unit increase or decrease does not fit the interaction. section 3.7.1
- Prefer st.text_input followed by float conversion when the number is virtually unbounded and no sensible step interval exists. section 3.7.1
places = st.number_input("Decimal places to round to", value=3, min_value=0)
Shows the compact implementation for a decimal-place control. section 3.7.1
