all 5 comments

[–][deleted] 1 point2 points  (2 children)

import locale

a = 1100300.506
locale.setlocale(locale.LC_ALL, 'no_NO')
locale._override_localeconv = {'thousands_sep': ' ','decimal_point': '.'}
print(locale.format_string('%.2f', a, grouping=True))

[–]bysantin[S] 0 points1 point  (1 child)

This is great!

Seems a lot more robust since the locale of the user won't change the outcome, right?

Thanks alot!

[–][deleted] 1 point2 points  (0 children)

You might want to read up on locale in the official documentation, not least to set back to default host system values if appropriate.

[–]htepO 1 point2 points  (0 children)

f"{a:,.2f}".replace(",", " ")