Format Integer With Comma Using Python Printf

I have built a slider that has integer values between, say, 0 and 2,000,000. I would like to display the numbers with thousands-commas-separator. The documentation states:

format (str or None) – A printf-style format string controlling how the interface should display numbers. This does not impact the return value. Valid formatters: %d %e %f %g %i

But it isn’t clear how I could accomplish this with the format argument.

Usually, in Python, this can be accomplished with:

x = 1000000
print(f"{x:,}")
# 1,000,000

Hey @Sean,

Welcome to the forum :wave:

We use the sprintf-js library to handle string formatting in the client.

I don’t believe this is currently possible, after looking at their documentation.

Feel free to file a feature request for this functionality!

However I’m not sure we’ll get to it right away, given the diversity of formats that could possibly be requested.

Also, we’ve started development on plugins, so this is something you should be able to build yourself in the near future!

Thanks @Jonathan_Rhone. Is there a way to convert the integer as a custom string?

Hey @Sean,

That’s not possible today but I created a new feature request for you.

1 Like