F
F
foonfyrick2020-11-26 09:26:07
Kotlin
foonfyrick, 2020-11-26 09:26:07

Why does var a:Double =0.0, a += 0.1 give an inaccurate result?

var a:Double = 0.0
    a += 0.1+0.1+0.1+0.1+0.1+0.1+0.1
   println( a)
//выводит 0.7

If we add another 0.1, it outputs 0.7999999999
then 0.8999999999
then 0.9999999999
then 1.0999999999
Why does it work like this?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
T
Timur Pokrovsky, 2020-11-26
@foonfyrick

https://0.30000000000000004.com/

V
Vasily Bannikov, 2020-11-26
@vabka

Because IEEE754

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question