Formatting Numbers

I’m working on an app to track grants, and I had some questions which IMHO should be very basic (and common) but I couldn’t find the answers anywhere. So here goes:

I’d like to format some numbers in a st.dataframe. I know I can do this in the pandas data frame, but I’d prefer not to so that I can sort correctly in the UI.

Anyway, here’s what I’d like to format:

  • Currency amounts with a leading $, two decimal places AND a comma separator at the thousands place.
  • Percents to one decimal place and a percent sign at the end.

I’d imagine these are pretty easy, and if I may suggest, could we add some of these to the docs?
Thanks for your help!!

2 Likes

There is a format argument to NumberColumn. It is poorly documented (to say the least) and apparently pretty limited, but AFAIK that is all you have.

You could also use pandas styles but that would mess up the sorting in the UI unles you add leading zeros. I think that is what you mean in the second paragraph.

Hi Goyo,
Are there additional format string examples that would solve my issues?
Thx

Tha only documentation I am aware of is in the link above. You can search the internet for printf (but that is C and this is probably some JS library that doesn’t work exactly the same), do some trial and error and see how far it gets you.

@Goyo I think you’ve hit on the issue that I’m having. Streamlit doesn’t really follow any one standard for this. I can’t imagine I’m the only person who has run into this issue.