Why (0.0015 * 3) == 0.0045 does not return true?

Asked

Viewed 54 times

1

Hello,

Because the comparison (0.0015 * 3) == 0.0045 in javascript does not return true?

Ex.:

var valor1 = 0.0015 * 3;
var valor2 = 0.0045;

if(valor1 == valor2) {
    console.log('Igual');
} else {
    console.log('Diferente');
}

  • You can also see more details: https://answall.com/q/38138/101

  • Because 0.0015 * 3 results in 0.0045000000000000005

  • @bigown has the same https://answall.com/q/154189/18246

  • if you make up to the 17th decimal place you will give EQUALS if( valor1.toFixed(17) == valor2.toFixed(17) ː see https://repl.it/KOZh/0

  • For the same reason that 0.1 + 0.1 is not 0.2, watch the video of the Infinite Series channel (in English): https://youtu.be/pQs_wx8eoQ8

No answers

Browser other questions tagged

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