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