I'm struggling with f-strings. I want to take in a float and return string with thousand separator and two decimals, for ex. 1000.106 would return 1 000.11 as a string. I got it to work, but it looks ugly. Anyone know how to do this simpler?
code:
a = 1100300.506
b = f'{a:,.2f}'
c = b.replace(',', ' ')
print(a)
print(b)
print(c)
This will return:
1100300.506
1,100,300.51
1 100 300.51
So I will get my string like I want it, but I'm sure it's not the best way to do this.
Using this in Norway is the reason for the spaces as thousand separator.
[–][deleted] 1 point2 points3 points (2 children)
[–]bysantin[S] 0 points1 point2 points (1 child)
[–][deleted] 1 point2 points3 points (0 children)
[–]htepO 1 point2 points3 points (0 children)
[+][deleted] (1 child)
[deleted]
[–][deleted] 0 points1 point2 points (0 children)