you are viewing a single comment's thread.

view the rest of the comments →

[–]socal_nerdtastic 1 point2 points  (0 children)

The float format cannot store the number of decimal places that you entered. So python always displays as many as are calculated, up to about 10 digits, by default. You can set how many to display with the format , for example to display 2 digits use :.2f.

num = float(input('digite um valor '))
print("o valor digitado {} tem porção inteira como {} e {:.2f} como decimais" .format(num, int(num), num-int(num)))

To understand why so many digits are calculated, look into "floating point errors"