Dear Yonghee Kim,

Floating point calculations are not exact because the decimal point is
represented by only a fixed number of binary digits. The more is the
bits allocated more will be the precision. This explanation would be
clearer if you see how to convert floating point integers to binary.
http://stackoverflow.com/questions/3954498/how-to-convert-float-number-to-binary

The series will be more and more accurate if more number of terms are
added and will each added term it error will decrease by 2^-(no of
terms). Furthermore this is the problem with almost every programming
language.

Regards,
Pranit Bauva

On Mon, Dec 28, 2015 at 3:29 PM, Yonghee Kim <masterpl...@gmail.com> wrote:
> I wrote simple code like this
>
> ----------------------
> a = 0.2
>
> for i in 1:10
>   println(a * i)
> end
> ---------------------------
>
>
> and what I got is not 0.2, 0.4, 0.6, 0.8, 1.0 ....
>
> but this.
>
> 0.2
> 0.4
> 0.6000000000000001
> 0.8
> 1.0
> 1.2000000000000002
> 1.4000000000000001
> 1.6
> 1.8
> 2.0
>
>
>
> println(0.2 * 3) does the same thing. not 0.6 but 0.6000000000000001
>
> does anyone know why this happens?

Reply via email to