liveBook · Manning

St.number_input

As explained in Build Python Web Apps with Streamlit

st.number_input is a Streamlit input element that collects a numeric value from a user.

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

How Build Python Web Apps with Streamlit covers it

How deep it goes
Explains syntax, defaults, minimum values, step buttons, and a widget-selection trade-off, but does not detail internal implementation.
Examples
Uses a unit converter’s decimal-place control, including default, minimum, step-button, and rounding behavior.
What it assumes
Assumes basic Python and Streamlit widget usage, while demonstrating numeric constraints and user-facing input choices.
What you can do after
Apply it via Streamlit to collect bounded numeric preferences and feed them into formatting logic.
How it connects
Connects numeric input with text input, rounding, validation, and step intervals.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Build Python Web Apps with Streamlit. The section links point to the parts of the book it draws on.