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.

>> 10
>> 10.0

Print float with commas as thousands separators and 2 decimals

 # Python2
# Python3
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.

#output: 2
#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.