I’m making an app that converts inches to millimeters.
If you look at the screenshot, it is inconvenient because the operation of entering a number, hitting the Enter key, deleting the existing number, and entering another number is repeated.
I was wondering how to make the input field blank before I press Enter and enter another number.
Is there a way to see the result rounded to 2 decimal places?
Are you talking about the on_change and on_click functions of the text?
I’d like to work around this by using the Enter key instead of using the submit button.
Please advise.
This method was discovered by chance,
My solution is ‘num = st.number_input(“”,value=1.0,format="%.1f ")’.
%f, %0.1d, %0.2f don’t matter.
The key is that you need a ‘space’ after the ‘f’.
This may be a coincidence, but for me it’s very useful.
When ‘space’ is removed, only the specified decimal point is kept and the rest is removed.
Nice you got it working. I can’t poke around as you haven’t posted the text. Please refer to this article next time you post a question as it helps the community and responders help you (e.g. point #3): Streamlit Components: how to post a question in the Streamlit forum
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking “Accept all”, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
Performance cookies
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
Functional cookies
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
Targeting cookies
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.