Entire division returning a different result than expected

Asked

Viewed 67 times

0

I’m having a problem with the entire division in python and R. The language returns a value other than "correct" in the entire division of 327 by 3.27 and the rest (%) different from 0 in these cases. (The image is python, but in R you get the same values, as I tested on my machine) Imagem

1 answer

2


The problem is that the computer is not very precise, is how you try to store 1/3 (there is as pq is an infinite decimal number, so it rounds and loses accuracy).

In that website explains better in the section "Quick word on Floating Point Arithmetic Issues".

What I did was multiply the value by 100 and then divide, because then it ceases to be decimal and becomes integer.

Exemplo do meu código

  • 1

    I was hunting for some explanation like that site, it was really worth!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.