> I mean, there’s a lot of things JavaScript should get heat for, but this really shouldn’t be one of them. This is inherently an issue with any language that has floating point numbers.
It is inherently an issue with binary floating point[1]. It is not an issue with decimal floating point. In decimal floating point, 0.1 + 0.2 = 0.3 exactly.
JavaScript could have used decimal floating point instead – but that would be slower, since it usually has to be emulated in software – mainstream platforms like x86 and ARM lack decimal floating point hardware, it is only found on rare platforms such as POWER, System z, and Fujitsu SPARC – and even with hardware acceleration it is still going to be slower. JavaScript, like most languages, prioritises speed over obviousness in this area.
Alternatively, JavaScript could have supported both decimal and binary floating point, and beginners could stick to the more obvious former, and those needing high performance could switch to the later – but its designers decided (probably correctly) that the added complexity wasn't worth it. (Also, having two types of floating point numbers in a language would likely confuse beginners just as much as binary floating point does.)
[1] And hexadecimal floating point too, but that is rarely encountered outside of IBM mainframes, and also various other obscure obsolete systems such as Interdata 8/32 minicomputers