10
Reply

what is the output for console.log(0.1 + 0.2); console.log(0.1 + 0.2 == 0.3);in JavaScript?

Abhishek Sharma

Abhishek Sharma

Jun 17, 2015
3.8k
1

    console.log(0.1 + 0.2 == 0.3); True

    Guru Bandgar
    May 23, 2016
    0

    console.log(0.1 + 0.2)=0.30000000000000004 & console.log(0.1 + 0.2 == 0.3)=false

    Abhijeet Gupta
    November 02, 2015
    0

    console.log(0.1 0.2)=0.300000000004 and console.log(0.1 0.2==0.3)= false

    pankaj dutt
    September 03, 2015
    0

    1. 0.10.2 2. false

    Srinivas Moka
    July 14, 2015
    0

    1. 0.30000000004 2. false

    Read once more :: An educated answer to this question would simply be: “You can't be sure. it might print out “0.3” and “true”, or it might not. Numbers in JavaScript are all treated with floating point precision, and as such, may not always yield the expected results.”The example provided above is classic case that demonstrates this issue. Surprisingly, it will print out: 0.30000000000000004

    Abhishek Sharma
    July 01, 2015
    0

    Also 0.1 + 0.2 == 0.3, This is also false, Because here it doesn't indicating typeOf check, Its totally different in floating point numbers.

    Abhishek Sharma
    July 01, 2015
    0

    alert(a == b);alert(a === b);"==" refers to equals check, while "===" also checks type.I think you made it wrong Abrar. What the question is... 0.2 +0.1 === 0.30000000000000004, Why? I know, everything in JS is object.

    Abhishek Sharma
    July 01, 2015
    0

    0.30000000000000004 false see below exmple. var a = "01"; var b = 01; alert(a == b) //object comparing ; alert(a === b) //object type comparing; output true false

    Abrar Ahmad Ansari
    July 01, 2015
    0

    Amazing question, and answer is also surprising. An educated answer to this question would simply be: “You can't be sure. it might print out “0.3” and “true”, or it might not. Numbers in JavaScript are all treated with floating point precision, and as such, may not always yield the expected results.”The example provided above is classic case that demonstrates this issue. Surprisingly, it will print out: 0.30000000000000004

    Abhishek Sharma
    June 17, 2015
    0