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

Itโ€™s a year old post and I was wondering if anyone was able to come up with a solution !?
Thanks,

3 Likes

I am also waiting for this function.

2 Likes

Same here!

3 Likes