Python Number Tutorials: Print Float with 2 Decimals and Thousand Separators, Int to Float

Python supports integers, floating-point numbers and complex numbers, which are int, float, and complex classes.

Convert between number data types

We can also use built-in functions like int(), float() and complex() to convert between types.

int(10.4)
>> 10
float(10)
>> 10.0
complex('4+6j')
(4+6j)

Print float with commas as thousands separators and 2 decimals

 # Python2
'{:,.2f}'.format(value) 
# Python3
f'{value:,.2f}'  
format(value, ',.2f')

Divide and get integer value

To get integer value of a division we use “//” operator. It returns floor value for both integer and floating point arguments.

7//3
#output: 2
9.0//4
#output: 2.0

Leave a Comment

Your email address will not be published. Required fields are marked *

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.

Close