Vincent
Vincent

Reputation: 1604

How to format a float with space between thousands, millions, etc

With :

pd.options.display.float_format = '{:,}'.format

It displays for number x = 1234567.888 :

1,234,567.888

What is the appropriate format to show 0 decimals and add a space between thousands, millions, billions, and so on ? Like this

1 234 568

Upvotes: 0

Views: 1981

Answers (1)

pragmaticprog
pragmaticprog

Reputation: 570

To perform this operation you are looking for using python, the following does the trick:

from math import trunc
some_float = 1234569.02

print ('{:,}'.format(trunc(some_float)).replace(',', ' '))

You can read more about trunc() here.

You can also use '{:,.0f}' to format, as pointed out by @Jon Clements. That does not require importing the math library.

Upvotes: 2

Related Questions