Abhishek Sharma
what is the output for console.log(0.1 + 0.2); console.log(0.1 + 0.2 == 0.3);in JavaScript?
By Abhishek Sharma in JavaScript on Jun 17 2015
  • Guru Bandgar
    May, 2016 23

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

    • 0
  • Abhijeet Gupta
    Nov, 2015 2

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

    • 0
  • pankaj dutt
    Sep, 2015 3

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

    • 0
  • Srinivas Moka
    Jul, 2015 14

    1. 0.10.2 2. false

    • 0
  • Pankaj  Kumar Choudhary
    Jul, 2015 2

    1. 0.30000000004 2. false

    • 0
  • Abhishek Sharma
    Jul, 2015 1

    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

    • 0
  • Abhishek Sharma
    Jul, 2015 1

    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.

    • 0
  • Abhishek Sharma
    Jul, 2015 1

    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.

    • 0
  • Abrar Ahmad Ansari
    Jul, 2015 1

    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

    • 0
  • Abhishek Sharma
    Jun, 2015 17

    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

    • 0


Most Popular Job Functions


MOST LIKED QUESTIONS